[Solved] Powershell – what’s this line saying?


Lets break apart this command

$currentuserid = Get-WmiObject -Class win32_computersystem -ComputerName $workstation | Select-Object -ExpandProperty Username

In powershell $ is the identifier for a variable. This means $currentuserid will equal the output of the last command in the pipe, In this case Select-Object.

Also in powershell -whatever after a command is a parameter.

The | symbol is pipe.

Get-WmiObject is a command making a WMI call to the win32_computersystem via the -class paramater, which is just some basic information about the computer system. -ComputerName parameter with the variable $workstation means do a remote WMI call to another computer which is unknown to me becuase i dont know whats inside the variable $workstation. The Output is then piped | to a select-object command which allows you to cut out data from a property. The parameter -ExpandProperty means to just return what the value of the property equals. The property value he wanted was Username

In simple terms it is getting the username from the Win32_computersystem class in a WMI call to a unknown remote system

1

solved Powershell – what’s this line saying?