troubleshooting Question

powershell can't recognize the cmdlt "Get-AzureAdAuditSigninLogs"

Avatar of Someone
Someone asked on
PowershellAzure
5 Comments1 Solution18 ViewsLast Modified:
Hey IT people

I'm trying to get last login info from azure ad using the cmdlt "Get-AzureAdAuditSigninLogs", but powershell doesn't seems to recognize the cmdlt.
I'm using the folllowing script:

$Cred = Get-Credential 
Connect-MsolService -Credential $Cred 
Connect-AzureAD -Credential $Cred 

$Users = Get-MsolUser -all 
$Headers = "DisplayName`tUserPrincipalName`tLicense`tLastLogon" >>C:\Temp\Users.txt 

ForEach ($User in $Users)    
{    
$UPN = $User.UserPrincipalName    
$LoginTime = Get-AzureAdAuditSigninLogs -top 1 -filter "userprincipalname eq '$UPN'" | select CreatedDateTime    
$NewLine = $User.DisplayName + "`t" + $User.UserPrincipalName + "`t" + $User.Licenses.AccountSkuId + "`t" + $LoginTime.CreatedDateTime    

$NewLine >>C:\Temp\Users.txt    
}

ASKER CERTIFIED SOLUTION
Saif Shaikh
Server engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros