Invoke-Command on remote session returns local values

后端 未结 2 2000
春和景丽
春和景丽 2021-01-15 13:45

Question

Should the script block of Invoke-Command, when run with a PSSession, always run on the remote computer?

Context

I ran the

2条回答
  •  春和景丽
    2021-01-15 13:46

    Pipe it to fl * or ft * so it doesn't use the format file to display the registry keys. The format file runs get-itemproperty locally to try to display the properties.

    From the bottom of $PSHOME\Registry.format.ps1xml for type Microsoft.Win32.RegistryKey:

    
      $result = (Get-ItemProperty -LiteralPath $_.PSPath |
          Select * -Exclude PSPath,PSParentPath,PSChildName,PSDrive,PsProvider |
          Format-List | Out-String | Sort).Trim()
      $result = $result.Substring(0, [Math]::Min($result.Length, 5000) )
      if($result.Length -eq 5000) { $result += "..." }
      $result
    
    

提交回复
热议问题