Connect to MSONline Tenant in o365

Welcome Forums General PowerShell Q&A Connect to MSONline Tenant in o365

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
1 year, 10 months ago.

  • Author
    Posts
  • #62338

    Participant
    Points: 0
    Rank: Member

    We manage a handful of clients in office 365 in our tenant. If I cannot to the MSOline service by entering this code 1 line at a time, it works every time. If i use it as part of an actual code block, if works about 50% of the time. Half the time it errors out Stating that "This cmndlet can only be run by partners", like the first connection line never actually happened.

    $UserCredential = Get-Credential
    
    $connectMsol = { 
    				
    				Connect-MSOLservice -Credential $UserCredential
    				$MSOLTenantid = (get-msolpartnercontract -DomainName domain.onmicrosoft.com).tenantid.guid
    				Connect-MSOLservice -Credential $UserCredential
    				}
    
  • #62742

    Keymaster
    Points: 1,673
    Helping HandTeam Member
    Rank: Community Hero

    If it's inconsistent like that, I'd honestly open a support incident with Microsoft. There's too much on their end we can't see to troubleshoot.

  • #62814

    Participant
    Points: 0
    Rank: Member

    I worked around it by manually setting that variable. Not ideal, but better than it working only some of the time.

The topic ‘Connect to MSONline Tenant in o365’ is closed to new replies.