question

DK-6243 avatar image
0 Votes"
DK-6243 asked AnshulKumarMINDTREELIMITED-5501 published

Powershell AzureAD

Hi,

I'm planning to create a ps script which connects to the MSOLService and then grab(Get user related information from MSOnline based on the parameters i set in the script. Executing the scripts would launch the authentication module and upon successful authentication would return the results.

Sample execution
./userinfo.ps1 <user>

Sample script
Connect-MsolService
$user = $args[0]
Get-MsolUser -Identity <$user> -Properties *

However, since the Connect-MsolService is defined in the script, i would need to authenticate each time i tried to search for user information . Is there a way that i would need to just authenticate once and skip authentication the next time i search for another user?

azure-ad-authentication
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, if the posted answer resolves your question, please mark it as the answer by clicking the check mark. Doing so helps others find answers to their questions.

0 Votes 0 ·

1 Answer

AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered

Hi @DK-6243 ,

you can try this:

 try {
     Get-MsolDomain -ErrorAction Stop 
 }
 catch {
     Connect-MsolService
 }


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.