getting prompted for credentials

%3CLINGO-SUB%20id%3D%22lingo-sub-3034279%22%20slang%3D%22en-US%22%3Egetting%20prompted%20for%20credentials%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3034279%22%20slang%3D%22en-US%22%3E%3CP%3EHello%3C%2FP%3E%3CP%3EI%20am%20using%20the%20below%20script%20to%20connect%20to%20exchange%20online%20and%20msolservice.%20When%20i%20run%20the%20script%20i%20am%20not%20prompted%20for%20credentials%20when%20connecting%20to%20exchange%20online%2C%20however%20i%20do%20get%20prompted%20for%20credentials%20when%20connecting%20to%20msolservice.%20I%20dont%20understand%20why%20i%20am%20getting%20prompted%20when%20connecting%20to%20msolservice%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%24pimserviceaccount%20%3D%20%22admin.mycompany.onmicrosoft.com%22%0A%24adminpassword%20%3D%20%2201000000d08c9ddf0115d1118c7a00c04fc297eb0100000084b78e199e1c3b478efd799c7aab6a910000000002000000000003660000c0000000100000000d19998b9fdab9ec1f44820c65de76fd0000000004800000a000000010000000dce05d1d250d5882967e46b97ecbd0c218000000ab0ceed45aa0a431a0137017b3479b6a6ea8e9694b41327714000000d1b19a01c628ceffedd753a5e2b53d0cd90fb930%22%0A%24secureString%20%3D%20ConvertTo-SecureString%20-String%20%24adminpassword%0A%24cred%20%3D%20New-Object%20-TypeName%20PSCredential%20-ArgumentList%20%24pimserviceaccount%2C%20%24secureString%0A%24Session%20%3D%20New-PSSession%20-ConfigurationName%20Microsoft.Exchange%20-ConnectionUri%20https%3A%2F%2Foutlook.office365.com%2Fpowershell-liveid%2F%20-Credential%20%24cred%20-Authentication%20Basic%20-AllowRedirection%0AImport-PSSession%20%24Session%20-DisableNameChecking%0AImport-Module%20msonline%0Aconnect-msolservice%20-credential%20%24cred%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3034279%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3073136%22%20slang%3D%22en-US%22%3ERe%3A%20getting%20prompted%20for%20credentials%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3073136%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1096811%22%20target%3D%22_blank%22%3E%40Skipster311-1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24orgName%3D%22%3CFOR%20example%3D%22%22%3E%22%0A%24acctName%3D%22%3CUPN%20of%3D%22%22%20the%3D%22%22%20account%3D%22%22%3E%22%0A%24credential%20%3D%20Get-Credential%20-UserName%20%24acctName%20-Message%20%22Type%20the%20account's%20password.%22%0A%23Azure%20Active%20Directory%0AConnect-MsolService%20-Credential%20%24credential%0A%23Exchange%20Online%0AImport-Module%20ExchangeOnlineManagement%0AConnect-ExchangeOnline%20-ShowProgress%20%24true%3C%2FUPN%3E%3C%2FFOR%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EThis%20should%20work%20if%20there's%20no%20MFA%2C%20examples%20are%20from%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fmicrosoft-365%2Fenterprise%2Fconnect-to-all-microsoft-365-services-in-a-single-windows-powershell-window%3F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fmicrosoft-365%2Fenterprise%2Fconnect-to-all-microsoft-365-services-in-a-single-windows-powershell-window%3C%2FA%3E%3C%2FP%3E%3CP%3Eand%20there%20are%20also%20examples%20with%20MFA%20if%20needed%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent Contributor

Hello

I am using the below script to connect to exchange online and msolservice. When i run the script i am not prompted for credentials when connecting to exchange online, however i do get prompted for credentials when connecting to msolservice. I dont understand why i am getting prompted when connecting to msolservice ?

 

$pimserviceaccount = "admin.mycompany.onmicrosoft.com"
$adminpassword = "01000000d08c9ddf0115d1118c7a00c04fc297eb0100000084b78e199e1c3b478efd799c7aab6a910000000002000000000003660000c0000000100000000d19998b9fdab9ec1f44820c65de76fd0000000004800000a000000010000000dce05d1d250d5882967e46b97ecbd0c218000000ab0ceed45aa0a431a0137017b3479b6a6ea8e9694b41327714000000d1b19a01c628ceffedd753a5e2b53d0cd90fb930"
$secureString = ConvertTo-SecureString -String $adminpassword
$cred = New-Object -TypeName PSCredential -ArgumentList $pimserviceaccount, $secureString
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking
Import-Module msonline
connect-msolservice -credential $cred

 

2 Replies

@Skipster311-1 

 

$orgName="<for example, litwareinc for litwareinc.onmicrosoft.com>"
$acctName="<UPN of the account, such as Email address removed>"
$credential = Get-Credential -UserName $acctName -Message "Type the account's password."
#Azure Active Directory
Connect-MsolService -Credential $credential
#Exchange Online
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -ShowProgress $true

This should work if there's no MFA, examples are from https://docs.microsoft.com/en-us/microsoft-365/enterprise/connect-to-all-microsoft-365-services-in-a...

and there are also examples with MFA if needed 

Did this work for you?