I\'m trying to compile the script to manually connect to each server and then perform the Powershell command remotely, and if the Powershell module is not found, then failback t
When running Invoke-Command against remote sessions, local variables from the calling session are not defined in the remote sessions. You either need to pass in those variables as arguments to a script block or use the using:
scope modifier. The syntax is $using:variable
.
In your case, the local variable is $_
. So you would need to use $using:_
.
Write-Host "Processing Server ... $($using:_) using DFSR Powershell Module" -ForegroundColor Yellow
Keep in mind that the using:
scope modifier only reads variables and does not allow writes.