windows - Powershell: Querying TS with Get-Process, SAMAccount and ComputerName? -
i'm trying code query ts specific applications , select sam account of user using process , computer name. have looks i'm having hard time integrating query of sam account , computer name.
get-wmiobject win32_process -computername "myserver" | {$_.name -eq "winword.exe"} | invoke-wmimethod -name getowner
you loose wmiobject process when pipe directly invoke-wmimethod
. can use foreach-object
generate object or use custom column select-object
this:
get-wmiobject win32_process -computername "localhost" | where-object {$_.name -eq "notepad.exe"} | select-object csname, processname, @{n="owner";e={$_.getowner().user}} csname processname owner ------ ----------- ----- frode-pc notepad.exe frode
when writing scripts custom columns, prefer write define them earlier more readable , can reused, this:
$ownercolumn = @{ name="owner" expression={ $_.getowner().user } } .... where-object ... | select-object csname, processname, $ownercolumn
Comments
Post a Comment