Forum / Remote Desktop Manager - PowerShell Repository

Office 365 Powershell

  • Create an Issue
  • Cancel

Hi Guys,

I want to make this script, that log my costumers in to office 365 with crendetials, from the password vault.


$User = $args[0]
$Pass = ConvertTo-SecureString -String $args[1] -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
Import-PSSession $Session
Import-Module MSOnline
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?

Thank you,
Martin

Clock3 yrs

Hi,

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:
https://jorgequestforknowledge.wordpress.com/2011/12/15/passwords-containing-special-characters-in-powershell/
http://www.coretekservices.com/20120216powershell-handling-reserved-characters-in-a-password/
https://powershell.org/forums/topic/dealing-with-dollar-symbol-within-secure-string-password/

Best regards,

Olivier Désalliers

signaturesignature

Clock3 yrs

Hi Oliver,

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 " ;-)

Any ideas?

Clock3 yrs

Hi,

How is formatted the values in $args[0] and $args[1]?

If you show the value of $args[0] or $args[1] 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/

Best regards,

Olivier Désalliers

signaturesignature

Clock3 yrs

Hi Oliver,

Sorry for late reply.

What do you mean by formatted? The $arg[0] 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[0], its empty, but i know it works, becuase it work perfect with passwords without special char. :-)

Thank you

Clock3 yrs

Hi,

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.

Best regards,

Olivier Désalliers

signaturesignature

Clock3 yrs