This repository was archived by the owner on Mar 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_BDSU-export_users.ps1
More file actions
102 lines (83 loc) · 3.6 KB
/
Copy path02_BDSU-export_users.ps1
File metadata and controls
102 lines (83 loc) · 3.6 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
. "$PSScriptRoot\utils.ps1"
. "$PSScriptRoot\00_config.ps1"
Ensure-AzureAD
Ensure-ExchangeCommands
$domain = $original_domain
Write-Host "Exportiere User-Liste"
$aadusers = @{}
Get-AzureADUser -All $true | Where-Object {$_.ProxyAddresses -like "*@$domain"} | ForEach-Object {
$aadusers[$_.UserPrincipalName] = $_
}
$mailboxes = Get-Mailbox -ResultSize Unlimited | Where-Object {$_.EmailAddresses -like "*@$domain"} | sort DisplayName
$import_csv = $mailboxes | Where-Object {
$_.UserPrincipalName -like "*@$domain" -and $_.RecipientTypeDetails -eq "UserMailbox"
} | ForEach-Object {
Write-Host $_.DisplayName
$aaduser = $aadusers[$_.UserPrincipalName]
[psCustomObject]@{
"User Name" = $aaduser.userPrincipalName
"First Name" = $aaduser.givenName
"Last Name" = $aaduser.surname
"Display Name" = $aaduser.DisplayName
"Job Title" = $aaduser.JobTitle
"Department" = $aaduser.department
"Office Number" = $aaduser.PhysicalDeliveryOfficeName
"Office Phone" = $aaduser.TelephoneNumber
"Mobile Phone" = $aaduser.Mobile
"Fax" = $aaduser.FacsimileTelephoneNumber
"Address" = $aaduser.StreetAddress
"City" = $aaduser.City
"State or Province" = $aaduser.State
"ZIP or Postal Code" = $aaduser.PostalCode
"Country or Region" = $aaduser.Country
}
}
$import_csv | Export-Csv -Encoding UTF8 -NoTypeInformation -Path P:\import-users.csv
& {
"Benutzername,Vorname,Nachname,Anzeigename,Position,Abteilung,Büronummer,Telefon (geschäftlich),Mobiltelefon,Faxnummer,Adresse,Ort,Bundesland/Kanton,Postleitzahl,Land oder Region"
Get-Content P:\import-users.csv | Select-Object -Skip 1
} | Set-Content -Encoding UTF8 -Path P:\import-users_de.csv
Write-Host "Exportiere erweiterte Postfach-Einstellungen"
$csv = $mailboxes | Where-Object {
$_.UserPrincipalName -like "*@$domain" -and $_.RecipientTypeDetails -eq "UserMailbox"
} | ForEach-Object {
Write-Host $_.DisplayName
$config = Get-MailboxRegionalConfiguration -Identity $_.UserPrincipalName
$proxyAddresses = $_.EmailAddresses | Where-Object {
$_ -ilike "smtp:*" -and $_ -notlike "*@bdsu-connect.de" -and $_ -notlike "*@BDSUev.onmicrosoft.com"
}
[psCustomObject]@{
UserPrincipalName = $_.UserPrincipalName
proxyAddresses = $proxyAddresses -join '|'
Language = $config.Language
DateFormat = $config.DateFormat
TimeFormat = $config.TimeFormat
TimeZone = $config.TimeZone
}
}
$csv | Export-Csv -Encoding UTF8 -NoTypeInformation -Path P:\mailbox-settings.csv
$extradomains = $csv | Where-Object {
$_.proxyAddresses -notlike "*@$domain"
}
if ($extradomains) {
Write-Warning "Folgende Benutzer haben zusätzliche E-Mail-Adressen mit anderen Domains"
$csv | ft -AutoSize UserPrincipalName,proxyAddresses
}
$nonprimaries = $mailboxes | Where-Object {
$_.UserPrincipalName -notlike "*@$domain"
}
if ($nonprimaries) {
Write-Warning "Folgende Postfächer wurden NICHT exportiert, da der Benutzername nicht die angegebene Domain verwendet"
$nonprimaries | ft -AutoSize Name,DisplayName,UserPrincipalName,RecipientTypeDetails,EmailAddresses
}
$sharedmailboxes = $mailboxes | Where-Object {
$_.RecipientTypeDetails -ne "UserMailbox"
}
if ($sharedmailboxes) {
Write-Warning "Folgende freigegebenen Postfächer wurden NICHT exportiert"
$sharedmailboxes | ft -AutoSize Name,DisplayName,UserPrincipalName,RecipientTypeDetails,EmailAddresses
}
if ($Host.Name -eq "ConsoleHost") {
Write-Host "Press any key to exit..."
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") > $null
}