I got stuck with this problem, I have tried many approaches I could not find any solutions.
I want to update a local variable from within the invoke-command.
example below:
I was looking to update the local $skip variable
$skip = '0'
$install = {
if($getversion.Version -eq $null) {
Write-Host -ForegroundColor Yellow "No agent found, installing the latest agent"
}
Elseif($getversion.Version -eq "0.3.9.328") {
Write-Host -ForegroundColor Yellow "Uninstalling old agent"
}
Elseif ($getversion.Version -eq "0.5.3004"){
Write-Host -ForegroundColor Green "Nagios is using the latest version..skipped"
$skip = '1'
Break
}
}
Invoke-Command -ComputerName WINSERVER -scriptblock $install