Hi
I’m looking for some power shell script to export all azure ad guest accounts that have not logged in from 60 days …

2 Spice ups

We’re happy to help, but not a script writing service.

What have you tried? where are you stuck?

If you post code, please use the ‘Insert Code’ button. Please and thank you!

codebutton_small.png

$Guest = Read-Host “Enter name of guest account”
$Guests = Get-AzureADUser -SearchString $Guest
ForEach ($G in $Guests) {
If ($G.UserType -eq “Guest”) {
$UserLastLogonDate = $Null
Try {
$UserObjectId = $G.ObjectId
$UserLastLogonDate = (Get-AzureADAuditSignInLogs -Top 1 -Filter “userid eq ‘$UserObjectId’ and status/errorCode eq 0”).CreatedDateTime }
Catch {
Write-Host “Can’t read Azure Active Directory Sign in Logs” }
If ($UserLastLogonDate -ne $Null) {
$LastSignInDate = Get-Date($UserLastLogonDate); $Days = New-TimeSpan($LastSignInDate)
Write-Host “Guest” $G.DisplayName “last signed in on” $LastSignInDate “or” $Days.Days “days ago” }
Else { Write-Host “No Azure Active Directory sign-in data available for” $G.DisplayName “(” $G.Mail “)” }
}}

The above one works, but I need someone who can help modify the script
I have a dump file of guest users that I need to import in the above script .

Not as read host. Import csv file

you need

Get-AzureADUser -Filter "UserType eq 'Guest'"

I’m looking for guest account in azure inactive for 60 days

I looked at your script and provided you information on how to filter guest user your script is already filtering users who didn’t log X number of days