none
Connect Office 365 Exchange Online through Powershell RRS feed

  • Question

  • I am trying to perform some operations on Exchange online(Office 365) through powershell.

    First I created a new powershell session and exported the modules to local as "o365", so that on any later operation I no need to use Import-PsSession to download the required modules

    $cred = Get-Credential
    
    $s = New-PSSession -ConfigurationName "Microsoft.Exchange" -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $cred -Authentication Basic -AllowRedirection
    
    Export-PsSession -session $s -outputModule o365
    

    -----

    Now, I am creating new session and importing the existing module "o365".

    $cred = Get-Credential
    
    $s = New-PSSession -ConfigurationName "Microsoft.Exchange" -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $cred -Authentication Basic -AllowRedirection
    
    Import-Module o365
    
    Get-DistributionGroup



    While running the command "Get-DistributionGroup", powershell prompts me to enter the office 365 credentials once again. Is it possible to avoid entering the credentials once again? I don't want to use Import-PsSession, since it takes more time.

    Wednesday, February 12, 2014 5:26 AM

All replies

  • Hi,

    Not sure, if the following cmdlets can make a difference. Anyway, suggest you to try these:

    $UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection Import-PSSession $Session

    Get-DistributionGroup



    Regards from ExchangeOnline.in|Windows Administrator Area | Skype:manuphilip@outlook.com


    • Edited by ManU PhiliP Wednesday, February 12, 2014 6:23 AM
    Wednesday, February 12, 2014 6:21 AM
  • I just ran into this issue and found I could get the exported module to use an existing session by passing it the session during the Import-Module statement with the -ArgumentList parameter.

    $Session = New-PSSession #OMITTED
    Import-Module O365 -ArgumentList $Session

    • Proposed as answer by Adam Weigert Thursday, October 16, 2014 2:29 PM
    Thursday, October 16, 2014 2:28 PM