powershell 远程执行命令(不用手动输入密码)

时间:2016-08-05 18:02:03   收藏:0   阅读:1962

$user = "domain\usrename"

$password = ConvertTo-SecureString -String "password" -AsPlainText -Force

$credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $user, $password

$session = New-PSSession -computer ip -credential $credential

$result = Invoke-Command -Session $session -ScriptBlock {Add-PSSnapin vm*}

$result = Invoke-Command -Session $session -ScriptBlock {get-desktopvm -pool_id olanddesk}

$result


连接远程服务器使用

enter-pssession -computer ip -credential domain\username


本文出自 “备忘录” 博客,请务必保留此出处http://flybozhou.blog.51cto.com/818675/1834767

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!