Hi Team,
I would like to create a CSV file for active users and inactive users. but I can create CSV file with only active users but not In-Active users.
$Output=foreach($sca in $scaColl)
{
if($sca.Email -ne "")
{
try{
$ActiveUser = Get-AzureADUser -ObjectId $sca.Email | Select-Object -Property DisplayName
Write-Host $ActiveUser.DisplayName;
New-Object -TypeName PSObject -Property @{
Title = $ActiveUser.DisplayName;
} | Select-Object Title
}
catch
{
New-Object -TypeName PSObject -Property @{
InActive = $ActiveUser.DisplayName;
} | Select-Object InActive
Write-Host "Invalid User"+ $ActiveUser.DisplayName
}
}
}
$Output | Export-Csv -Path D:\CSV\myVar.csv -NoTypeInformation
From the Try method, i can log with active users, but from the catch method, i can not create another column to add in-active users
cany any one can assist me how to bind properly with above code.
Murali KrisPosted Dec 7, 2021, 2:30 PM
Hi Srinivas,
Can you please copy the existing code and update/align the code, as I am not an expert on how to log active and inactive users in CSV File, hence I have posted the existing code. can you please update?
When the user is not found in AD, then it goes to the catch method, only how can we direct/restrict the code to log Inactive users without a catch.
We used catch bcause if there is any error means if the user is not found in AD then only it throws a very long error, to formate with custom error with Inactive.
Can please add your inputs on updating the code.
Srinivasan RamamoorthiPosted Dec 6, 2021, 3:17 PM