将交换管理会话导入PowerShell

时间:2016-05-27 16:08:36

标签: powershell

我使用gui

从用户那里获得用户凭证
$userid =$email.text
$password = $Password.text
$Session = New-PSSession -Authentication default -credential($userid,$passowrd) -ConnectionUri https://$ip/powershell -ConfigurationName Microsoft.Exchange -SessionOption (New-PSSessionOption -SkipCNCheck -SkipCACheck)
        Import-PSSession $Session

当我将用户名和密码传递给会话变量时,它会抛出错误 我如何传递这两个值,以便可以将交换管理会话导入powershell

1 个答案:

答案 0 :(得分:1)

试试这个

$userid = $email.text
$password = $Password.text | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential -ArgumentList $userid, $password

$Session = New-PSSession -Authentication default -Credential $credential -ConnectionUri https://$ip/powershell -ConfigurationName Microsoft.Exchange -SessionOption (New-PSSessionOption -SkipCNCheck -SkipCACheck)
Import-PSSession $Session