I have the following script I'm trying to modify to include two additional Properties of EmployeeID and SAMAccountName to be included in the CSV export. I've tried isolating the EmployeeID and SAMAccountName variables several ways and none seem to pass the value to the export.
Import-Module ActiveDirectory
$Users = ForEach ($U in (Get-ADUser -Filter {Enabled -eq "True"}))
{
$SM = (Get-ADUser -Properties * | Select SAMAccountName)
$ID = (Get-ADUser $U $textfield1.text -Properties * | Select EmployeeID)
$UN = Get-ADUser $U -Properties MemberOf
$Groups = ForEach ($Group in ($UN.MemberOf))
{
(Get-ADGroup $Group).Name
}
$Groups = $Groups | Sort
ForEach ($Group in $Groups)
{
New-Object PSObject -Property @{
Name = $UN.Name
UserName = $SM
EmployeeID = $ID
Group = $Group
}
}
}
$Users | Export-CSV C:\scripts\UserMemberships.csv
any help would be appreciated on where I'm going wrong.