我终于做到了T-T
执行远程脚本,
这一刻,我花了半年......
德玛西亚!
大致思路:
$passwd = "Demacia!!!!"
$sePasswd = ConvertTo-SecureString $passwd -AsPlainText -Force
$cred=New-Object System.Management.Automation.PSCredential("administrator",$sePasswd)
$s = New-PSSession -ComputerName 192.168.1.9 -Credential $cred
invoke-command -session $s -scriptblock {cd C:\Users\administrator\Desktop;cscript write.vbe}
另存为ps1文件,使用powershell打开即可。
当然,之前目标机器必须要先打开WinRM服务,具体看此处:
#使本机器可以执行ps1文件
set-executionpolicy remotesigned
#是否要通过本计算机上的 WinRM 服务启用远程管理?
Set-WSManQuickConfig
#关闭防火墙
Enable-PSRemoting –Force
#添加信任IP
cd wsman::localhost\client
Set-Item TrustedHosts "10.2.1.9"
#远程该IP
Enter-PSSession -ComputerName 10.2.1.9 –Credential Administrator
以上。感谢您的阅读。欢迎给我评论。
参考文档:
http://www.cnblogs.com/dreamer-fish/p/3989899.html 该文讲了一些密码加密的知识