powershell - Property is empty when run through Invoke-Command -
i trying individually monitor memory usage of process (w3wp.exe
) has multiple instances of filtering out string found in process' commandline
property.
it works when run script locally:
$proc = (wmiobject win32_process -filter "name = 'w3wp.exe'" | where-object {$_.commandline -like "*sometextfromcl*"}) $id = $proc.processid $ws = [math]::round((get-process -id $id).ws/1mb) write-host $ws
however, when try run remotely through invoke-command
, error telling id
property's value null:
cannot bind argument parameter 'id' because null. + categoryinfo : invaliddata: (:) [get-process], parameterbindingvalidationexception + fullyqualifiederrorid : parameterargumentvalidationerrornullnotallowed,microsoft.powershell.commands.getprocesscommand + pscomputername : remoteservername
my invoke-command
syntax is:
invoke-command -computername remoteservername -filepath script.ps1 -credential $mycredential
i'm sure it's simple i'm ps after long absence , had around couldn't find helpful.
you writing answer console. use ps1 function, should use:
return $ws
instead of
write-host $ws
Comments
Post a Comment