Powershell AzureAD

D K 1 Reputation point
2021-07-05T10:15:20.677+00:00

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?

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,665 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Andreas Baumgarten 97,566 Reputation points MVP
    2021-07-05T10:51:17.543+00:00

    Hi @D K ,

    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

    0 comments No comments