Reputation: 31
I get user credential from user using 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
when i pass user name and password to session variable it's throw an error how can i pass this two value so that can import exchange management session to powershell
Upvotes: 0
Views: 64
Reputation: 2001
try this
$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
Upvotes: 1