-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADExportUsr.ps1
38 lines (36 loc) · 1.48 KB
/
ADExportUsr.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#Export information users's from AD in .csv
#Nicolas Martinelli
#Set you Organizational Unit
$OrganizationalUnit = "Insert you OU"
#Set Output Path
$output = "insert your output path and file name.csv"
#Initialize Array
$ObjectOutput =@()
$Prop =@()
#Extract Information from Active Directory
Write-host "Collecting information...please wait" - foreground "Yellow"
$List = Get-ADUser -Filter * -Properties DisplayName,samaccountname,department,employeeType,CanonicalName,PasswordLastSet,Enabled,accountExpires,AccountExpirationDate,whenCreated,whenChanged,LastLogonDate,extensionAttribute3,memberof -searchbase $OrganizationalUnit -searchscope 2
Foreach ($i in $List){
$MO = $i.MemberOf
$GroupMembership = ($MO | % { (Get-ADGroup $_).Name; }) -join ',';
#Set properties
$info = @{
Gruppo = $GroupMembership
DisplayName = $i.DisplayName
SamAccountName = $i.samaccountname
Department = $i.department
employeeType = $i.employeeType
CanonicalName = $i.CanonicalName
PasswordLastSet = $i.PasswordLastSet
Enabled = $i.Enabled
accountExpires = $i.accountExpires
AccountExpirationDate = $i.AccountExpirationDate
whenCreated = $i.whenCreated
whenChanged = $i.whenChanged
LastLogonDate = $i.LastLogonDate
extensionAttribute3 = $i.extensionAttribute3
}
$ObjectOutput += New-Object -TypeName PSobject -Property $info
}
Write-host "Exporting information in .csv file" -foreground "Yellow"
$ObjectOutput | Export-csv FinalTest.csv -Delimiter ";" -NoTypeInformation