如何调用驻留在目标计算机上的ps1文件?所有教程大多说我在远程机器上运行本地ps1。我尝试了以下但它什么也没做:/
$username = "theusername"
$password = "thepassword"
$secpassword = ConvertTo-SecureString –String $password –AsPlainText -Force
$credential = New-Object –TypeName "System.Management.Automation.PSCredential" –ArgumentList $username, $secpassword
$so = New-PSSessionOption -SkipCACheck
$session = New-PSSession -ConnectionUri "https://servername:5986/WSMAN" -SessionOption $so -Credential $credential
Invoke-Command -Session $session -ScriptBlock { "powershell E:\\Tools\Powershells\MyPowershell.ps1" }
Exit-PSSession
答案 0 :(得分:2)
按路径(可能带空格)执行脚本是用
完成的Invoke-Command -Session $session -ScriptBlock { & "path with spaces\script.ps1" }
这在远程工作时同样适用,因此要执行远程存储的远程脚本,请使用
withStyles(styles)(YourTable)