I am trying to execute a simple Test-Path query to a remote computer using Invoke-Command, but I am struggling with a strange error.
This w
You have a scope issue. The scope within the script block that runs on the remote server cannot access your local variables. There are several ways around this. My favorite is the $Using: scope but a lot of people do not know about it.
$p_FileName = "c:\windows\system.ini"
Invoke-Command -ComputerName COMPUTER001 -ScriptBlock {Test-Path -Path $Using:p_FileName}
For invoke command, this lets you use local variables in the script block. This was introduced for use in workflows and can also be used in DSC script blocks.