I have a script to get users information from the Active directory. It will first get the names of the users then store it in a variable before passing it through a foreach loop to get the details of each account. The script can be run but the CSV file is empty. The following is the script. Appreciate the help.
PROCESS{
$path = "C:\Users\Administrator\CSVReports"
$reportdate = Get-Date -Format ddmmyyyy
$csvreportfile = $path + "\ALLADUsers_$reportdate.csv"
$Admins = (Get-ADGroupMember -Identity Administrators | select-object Name)
Foreach( $i in $Admins){
$UserDetails= Get-ADUser -Filter "Name -eq '$i'" -Properties * | select-object DisplayName, samaccountName, Enabled, Created, LastLogonDate | sort-object -Property LastLogonDate
}
$UserDetails | Export-Csv -Path $csvreportfile -NoTypeInformation
}