none
Using connect-msolservice and $msoltenantid via powershell script for office 365 RRS feed

  • Question

  • Hi,

    I've got a script that I've set up to allow me to connect to any of our clients' Office 365 powershell consoles using partner portal credentials.

    However, I've been unsuccessful in adding the connect-msolservice command and $MSOLTenantid variable into the script. If I run the command myself in the powershell session, it works just fine. However, it seems to ignore these two commands in the script, and I'm not sure why. It works fine through line 6.

    Here's the script:

    Get-ExecutionPolicy
    Set-ExecutionPolicy remotesigned
    $LiveCred = Get-Credential 
    $Tenant = Read-Host -Prompt 'Input the Tenant name'
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/PowerShell-LiveID?DelegatedOrg=$Tenant.onmicrosoft.com -Credential $LiveCred -Authentication Basic –AllowRedirection 
    Import-PSSession $Session
    
    Connect-MSOLservice -Credential $LiveCred
    $MSOLTenantid = (get-msolpartnercontract -domain $Tenant.onmicrosoft.com).tenantid.guid

    • Moved by Bill_Stewart Wednesday, July 26, 2017 7:33 PM Don't be a "cargo cult" programmer
    Wednesday, June 14, 2017 4:19 PM

All replies

  • Not sure why you are using New-PsSession.   It won't do anything useful and will likely cause an error.

    You do not need to set execution policy and that never works in a script if the policy is already set to restrictive.


    \_(ツ)_/

    Wednesday, June 14, 2017 6:53 PM