I want to make this script, that log my costumers in to office 365 with crendetials, from the password vault.
$User = $args
$Pass = ConvertTo-SecureString -String $args -AsPlainText -Force
$PSCred = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $Pass
$LiveCred = Get-Credential -Credential $PSCred
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Connect-MsolService -Credential $LiveCred
Nothing secret there. Everything works, i get online.
But when take a costumer, where i use the harder password, with special charecteres, it fails.
Anyone know what to do?
I suspect the special characters in the password to be the problem. You need to escape the special characters.
You can read about it in these articles:
Thank you so much for your answer.
The issue with esacpe chareters is i dont think i see where i can use them.
If i use them like this $PSCred = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList "$User", "$Pass"
Then it will see it as the string $user .. So the only way, is to write them directly in the password vault.
Then everypassword will be "Thisis@realPa$$word". Then we meet the issue when i copy the password for anything else, becuase the password is without " ;-)
How is formatted the values in $args and $args?
If you show the value of $args or $args in PowerShell. Is it the the right username or password or the characters are already wrong?
If you put a string in single quotes, for example 'Thisis@realPa$$word' and convert it to secure string it will work but if you put it between double quotes it won't as explained in the site I linked to you: https://jorgequestforknowledge.wordpress.com/2011/12/15/passwords-containing-special-characters-in-powershell/
Sorry for late reply.
What do you mean by formatted? The $arg reffer to the setting in probeties that says username, and 1 reffer to password. The username and password is picked up from the Password vault.
I get what you mean by the single qoutes, but i dont understand where you want me to write them.
If i echo $arg, its empty, but i know it works, becuase it work perfect with passwords without special char. :-)
When you say you get the username and password from the Password Vault, you mean that you use the Remote Desktop Manager module because the module is not available in Password Vault Manager.
Thus to get the username you wrote $session.Username and to get the password you use Get-RDMSessionPassword -Session $session?
$session is variable that contains a session that you got by using Get-RDMSession.