I need to test if users are member of a security group and if they are not do something.
I have the test part done, but I am trying to get the User Name and LastLogonDate to export to a CSV file. The Write-Host are there for testing..
$Users = get-aduser -Filter * -searchbase $InactiveUsersOU -Properties * | Where {$_.Enabled -eq $True} | Where {$_.LastLogonDate -lt $(Get-Date).AddDays(-90)} ForEach ($User in $Users) { If ($User.MemberOf -contains $CN) { Write-Host "Member, Skip" Write-Host $User.Name } Else { Write-Host "Not a Member" Write-Host $User.Name, $User.LastLogonDate select $User.Name, $User.LastLogonDate | Sort User.LastLogonDate | Export-Csv $ReportPath\$FileDate"InactiveUsers.csv" -NoTypeInformation } }
My brain if full, its after lunch, and that led me here....