电源外壳远程连接

时间:2018-10-29 20:35:42

标签: powershell remote-connection window-server

$command = {
     {& C:\Users\mnmicrostrategy\Desktop\MSTRTrigger\TCargaVenda.bat}
}
 $user = "jkf\badumtsss"
 $password = "pass"
 $target = "APOLLO"

$secpassword = $password | ConvertTo-SecureString -AsPlainText -Force
$creds = New-Object ystem.Management.Automation.PSCredential($user,$secpassword)
Invoke-Command -ComputerName $target -Credential $creds -ScriptBlock {$command}

我试图在本地计算机上运行上述powershell脚本,以在名为“ APOLLO”的Windows服务器计算机上连接并执行.bat脚本

当我在服务器上手动运行.bat时,执行成功,并且收到通知电子邮件,但是,当我从Power Shell脚本运行到远程连接并执行.bat时,没有错误,并且什么都没发生。

PS:我在本地计算机上具有powershell -executionpolicy remotesigned。

一些帮助将不胜感激。 谢谢大家。

1 个答案:

答案 0 :(得分:0)

以下脚本对我有用,谢谢!

 $user = "jfk\baduntsss"
 $password = "ueaohuheaou"
 $target = "APOLLO"

 $secpassword = $password | ConvertTo-SecureString -AsPlainText -Force
 $Creds = New-Object 
 System.Management.Automation.PSCredential($user,$secpassword)

 Invoke-Command -ComputerName $target -Credential $Creds -ScriptBlock {& 
 C:\Users\mnmicrostrategy\Desktop\MSTRTrigger\TCargaVenda.bat}