Avatar of Someone
Someone
 asked on

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

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    
}

Open in new window


PowershellAzure

Avatar of undefined
Last Comment
Saif Shaikh

8/22/2022 - Mon
Seth Simmons

is it installed?

Install-Module -Name MSOnline

Open in new window


if it is, try loading it in the beginning of your script

import-module MSOnline

Open in new window

ASKER CERTIFIED SOLUTION
Saif Shaikh

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Someone

ASKER
Seth Simmons 

still doesn't work
Someone

ASKER
Saif Shaikh 

I love you man
I've tried to install AzureADPreview  module before but without the other options "-AllowClobber -Force " and it didn't work.
now it works!
thank you
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Saif Shaikh

I love you too....hahahaahha