Office 365 Powershell

avatar

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

All Comments (5)

avatar

Olivier Désalliers

avatar

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?

avatar

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

avatar

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

avatar

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