Forum Discussion
robertglass
Sep 01, 2021Copper Contributor
MFA for users from ou to csv file
hi i am trying to modify my mfa script to include more than the upn and if MFA is enabled and wanted to include the description and when created date from AD. unfortunately it creates the CSV files w...
robertglass
Sep 02, 2021Copper Contributor
i finally found a way round my issue and this is the script i ended up with thanks for peoples input it helped me figure it out.
below is a copy of how my script ended up and provides a csv file with the attributes i needed. hopefully sharing it will be useful to others.
$Users = Get-ADUser -Filter * -SearchBase 'OU=test,DC=Dc,DC=net' |
Get-ADUser -Properties mail | where {$_.mail -ne $null} |
Select-Object -ExpandProperty UserPrincipalName
$Report = [System.Collections.Generic.List[Object]]::new() # Create output file
Write-Host "Processing" $Users.Count "accounts..."
foreach( $user in $users ){
$msousers = Get-MsolUser -UserPrincipalName $User
foreach ($msouser in $msousers) {$ReportLine = [PSCustomObject] @{
User = $msouser.UserPrincipalName
Name = $msouser.DisplayName
created = $msouser.whencreated
Jobtitle = $msouser.title
MFAstatus = $msouser.StrongAuthenticationRequirements.State
} }
$Report.Add($ReportLine)
}
$Report | Sort User | Export-Csv -Path 'C:\Temp\UK-MFA Report.csv' -NoTypeInformation