StevensNet.com

...Because someone's gotta tell the story...

Blogs

To return to the main Blog List, click Full Blog Listing.

Tags

PowerShell
Registry

Powershell: Getting the locally logged in user (as SYSTEM)

Tuesday, April 16, 2013 in Powershell (Views: 1359)
Sometimes as you are scripting you need to get the locally logged on user, perhaps to drop a file on the desktop, or edit the HKU registry hive. You can easily do this by a WMI query.

In this example, I have removed the domain name (in this case, called DOMAIN).

$LocalUser=Get-WmiObject -Query "Select UserName from Win32_ComputerSystem"
$LocalUser.UserName=$LocalUser.UserName.Replace("DOMAIN\","")
write-host "Local User Is: "$LocalUser.UserName


Happy Scripting.

 

Related Blogs You May Be Interested In:


To leave a comment, please log in and/or register.