-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExport-ADtoCSV.ps1
49 lines (39 loc) · 1.33 KB
/
Export-ADtoCSV.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
39
40
41
42
43
44
45
46
47
48
49
<#
.SYNOPSIS
Export AD properties to CSV.
.DESCRIPTION
This script will export selected AD properties from given company to a CSV file
.PARAMETER MyCompany
filter for the specific company being exported
.PARAMETER Path
location to put output files
.PARAMETER Path2
location to put output files for a second directory if needed
.PARAMETER OutCSV
named of csv to use
.EXAMPLE
.\Export-ADtoCSV.ps1 -OutputDirectory 'C:\tmp\'
This would change the default output directory location from the default of home directory
#>
Param
(
[string]$MyCompany='CompanyName',
[string]$Path='\\server\directory\Records\forms\dir1',
[string]$Path2='\\server\directory\Records\forms\dir2',
[string]$OutCSV='.\example.csv'
)
$users = Get-ADUser -Filter {Company -eq "$MyCompany"} -Properties sn, givenName, displayName, description, Title | where {$_.Enabled -eq $true } | select Name, sn, givenName, displayName, description, Title
$dir1 = Get-ChildItem -Path "$Path" | Select-Object name
# $dir2 = Get-ChildItem -Path "$Path2" | select-object name
$outFile = @($users,$dir1)
foreach($file in $dir1)
{
# $noExt = $file.substring(0,$file.length-3)
$noExt = $file.Basename
# if(($users.Name) -match $_.file)
if(($users.Name) -match $noExt)
{
$output += ($users,$file)
}
}
$outFile | ConvertTo-CSV | Out-File $OutCSV