Invoke-Command won't accept -Path as a variable

前端 未结 3 1179
无人及你
无人及你 2020-12-12 00:01

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

3条回答
  •  余生分开走
    2020-12-12 00:24

    You have to pass local variables used in the script block through the -ArgumentList parameter:

    $p_FileName = "c:\windows\system.ini"
    Invoke-Command -ComputerName COMPUTER001 -ScriptBlock {Test-Path -Path $args[0]} -ArgumentList $p_FileName
    

提交回复
热议问题