I've wrote the following code; the purpose of the code is to get the following fields from Active Directory and push it to a CSV file. Below is the code:
# Importing Active Directory Modules
Import-Module ActiveDirectory
# Declaring the File Path of where the Host File will be generated.
$csvfile = "C:\TEMP\EmployeeFiles.csv"
# Get the only following fields from Active Directory
Get-ADUser -Filter * -Properties Enabled, EmployeeID, GivenName, Surname, title, Company, Manager, BusinessCategory, Mail, Mobile, streetAddress, physicalDeliveryOfficeName, st, co, PostalCode, chpositionID |
Where-Object {$_.Enabled -eq $True} |
select EmployeeID, GivenName, Surname, title, Company, Manager,
BusinessCategory, Mail, Mobile, streetAddress, physicalDeliveryOfficeName,
st, co, PostalCode, chpositionID |
Select-Object @{Label = "Employee ID";Expression = {$_.EmployeeID}},
@{Label = "First Name";Expression = {$_.GivenName}},
@{Label = "Last Name";Expression = {$_.Surname}},
@{Label = "Title";Expression = {$_.title}},
@{Label = "Organisation";Expression = {$_.Company}},
@{Label = "Supervisor";Expression = {$_.Manager}},
@{Label = "Business Unit";Expression = {$_.BusinessCategory}},
@{Label = "Email";Expression = {$_.Mail}};
@{Label = "Mobile";Expression = {$_.Mobile}},
@{Label = "Business Address";Expression = {$_.streetAddress}},
@{Label = "Business City";Expression = {$_.physicalDeliveryOfficeName}},
@{Label = "Business State";Expression = {$_.st}},
@{Label = "Business Country";Expression = {$_.co}},
@{Label = "Business Postcode";Expression = {$_.Postalcode}},
@{Label = "Position";Expression = {$_.chpositionID}} |
Export-Csv $csvfile -NoTypeInformation
However, the code runs and generates the CSV file; but the CSV file contains the following information:
"IsReadOnly","IsFixedSize","IsSynchronized","Keys","Values","SyncRoot","Count" "False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","2" "False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","2" "False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","2" "False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","2" "False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","2" "False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","2" "False","False","False","System.Collections.Hashtable+KeyCollection","System.Collections.Hashtable+ValueCollection","System.Object","2"