将以下命令按照需要修改之后保存为powershell脚本文件,运行即可通过远程登录powershell在服务器上执行需要的操作
$uname="administrator" #administrator为用户名 $pwd=ConvertTo-SecureString "111111" -AsPlainText -Force; #111111为密码 $cred=New-Object System.Management.Automation.PSCredential($uname,$pwd); #创建自动认证对象 $pcname="192.168.44.129" Enter-PSSession -ComputerName $pcname -Credential $cred #登录 "This is an autolink script which generates auto login feature!" #Invoke-Command -scriptblock {ipconfig} -Credential $cred -ComputerName $pcname #-scriptblock是用来执行单个命令 #Invoke-Command -FilePath C:\runme.ps1 -Credential $cred -ComputerName $pcname #-filepath是用来执行脚本文件中的命令
本文链接: https://www.pstips.net/auto-login-and-invoke-remoting-command.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!