How can i get: (works)
$Procname = 'notepad'
Invoke-Command -ComputerName sandbox -ScriptBlock {
if ((Get-Process | Where-Object {$_.Name -eq $Procname}) -eq $null) {
Write-Host 'null' -ForegroundColor Red
} else {
Write-Host running -ForegroundColor Green
}
}
Too look like this? (no work)
$Procname = 'notepad'
$chk = (Get-Process | Where-Object {$_.Name -eq $Procname})
Invoke-Command -ComputerName sandbox -ScriptBlock {
if ($chk -eq $null) {
Write-Host 'null' -ForegroundColor Red
} else {
Write-Host running -ForegroundColor Green
}
}
The trouble i am having is getting the Get-process | where-object to run from outside the scriptblock, I can pass text OK from outside the scriptblock (IE the $Procname) but i am trying to pass the command, what special things do i need to do?
I have asked uncle google, but I think I'm asking the wrong question.
I have also tried $chk as a Param and an arg but they didn't work for me