Hello everyone,
I was trying to create a PowerCli script to alter the output of the Get-process cmdlet depending on how much memory the process was using. Here's the script that I attempted:
$a=Get-VM | Where-Object {$_.PowerState -eq "PoweredOn" -and $_.Guest.OSFullName -like "*Windows*"} | Invoke-vmscript -scripttext
"get-process"-guestuser administrator -guestpassword password | Write-output
foreach ($i in $a){
if ($i.WorkingSet -gt 10000) {
write-host $i.ProcessName, $i.workingset -foregroundcolor "red"}
else {write-host $i.processName, $i.workingset}
}
I'm using the Invoke-VMScript because for some reason or another I'm not able to Get-Process remotely to another machine and receive the "Get-Process: Couldn't connect to remote machine" error. I'm able to execute Get-WMIObject cmdlets remotely without any issue so I wasn't sure what kind of configuration troubles were to be had. After a bit of research I wasn't able to fix it and so I settled with this.
The script runs successfully but then ends without any output at all. When I execute only:
Get-VM | Where-Object {$_.PowerState -eq "PoweredOn" -and $_.Guest.OSFullName -like "*Windows*"} | Invoke-vmscript -scripttext
"get-process"-guestuser administrator -guestpassword password | Write-output
it's able to display the process lists of all VMs on the Host. I'm guessing there might be something wrong with the latter part of the script.
Any feedback would be greatly appreciated and please feel free to comment if you might know of any tips or tricks at all.
Best regards