Connecting to Office 365 Powershell

avatar

Hello

I would like to connect to various Office 365 powershells directly from RemoteDesktopManager. My problem is the credential delivery. Normally I get the credentials with:

$LiveCred = GetCredential

Then a credential window pops up and I have to enter the crendetials of the Office 365 account I wish to connect with.

But I want to enter the credentials in the connection setting in RDM and call them together with the script. I have searched for other possibilities and found a way to setup the PSCredential manually from command line options, wich I can feed with RDM:

$User = $args[0]

$Pass = ConvertTo-SecureString -String "$args[1]" -AsPlainText -Force

$LiveCred = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $Pass

But I get allways an error connecting to the Office 365 remote powershell (no access). Any ideas?

The complete script I call from RDM looks like this:

---$User = $args[0]

$Pass = ConvertTo-SecureString -String "$args[1]" -AsPlainText -Force

$LiveCred = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $Pass

$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

---

Oliver

edited by OTimme on 6/12/2013

All Comments (66)

avatar

Added the following to the script... need to convert the PSCredential to a Credential

$LiveCred = Get-Credential -Credential $PSCredI think it works, got passed the authentication but then failed (see error below)

$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

edited by stefane on 6/12/2013

Stéfane Lavergne