-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgradeDL.ps1
More file actions
90 lines (68 loc) · 4.62 KB
/
Copy pathupgradeDL.ps1
File metadata and controls
90 lines (68 loc) · 4.62 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
# $login = "Email@domain.com"
$FolderPath = ([Environment]::GetFolderPath('MyDocuments'))
$PWlist = (Get-ChildItem $FolderPath | Where { $_.Name -match '_encrypted_password1.txt'} )[0].VersionInfo.filename
IF ($PWlist) { $login = (([string]$PWlist -split "\\")[-1] -split '_')[0] }
#$login = ([adsi]"LDAP://$(whoami /fqdn)").mail
$credpath = $([String]$FolderPath + '\' + $login + '_encrypted_password1.txt')
#Ask for credentials and store them
IF(Test-Path $credpath)
{
$encrypted = Get-Content $credpath | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PsCredential($login, $encrypted)
try { Connect-ExchangeOnline -Credential $credential } catch { Connect-ExchangeOnline -UserPrincipalName $login }
}
ELSE {
$credential = Get-Credential $login
$credential.Password | ConvertFrom-SecureString | Out-File $credpath
# Read encrypted password
# Set variables
try { Connect-ExchangeOnline -Credential $credential } catch { Connect-ExchangeOnline -UserPrincipalName $login }
}
# slow
$Menu = Get-DistributionGroup | select DisplayName,Name,@{n= "Members";e={((Get-DistributionGroupMember $_.distinguishedname).count)}},alias,PrimarySmtpAddress,DistinguishedName,GUID
$DL = $Menu | Out-Gridview -Outputmode Single -T "Select Distributionlist to Upgrade"
# fast
# $DL = Get-DistributionGroup | select Disp*e,alias,pri*,Name,GUID,distinguishedname | Out-Gridview -Outputmode Single -T "Select Distributionlist to Upgrade"
$Path = [Environment]::GetFolderPath('MyDocuments')
$DL | Export-Csv -Path "$Path\DL_$($DL.Name).csv" -NoTypeInformation -Encoding UTF8 -Force ; $DL
$Members = Get-DistributionGroupMember -Identity $DL.distinguishedname -ResultSize Unlimited
$Members | Export-Csv -Path "$Path\exportDL_$($DL.Name).csv" -NoTypeInformation -Encoding UTF8
$Members | select *name*,alias,pri*,GUID | Export-Csv -Path "$Path\exportDLshort.csv" -NoTypeInformation -Encoding UTF8 -Force
Remove-DistributionGroup -identity $DL.DistinguishedName
sleep 5
New-UnifiedGroup -name $DL.Name -Alias $DL.Alias -PrimarySmtpAddress $DL.PrimarySmtpAddress -DisplayName $DL.DisplayName
Set-UnifiedGroup -Identity $DL.Name -DisplayName $DL.DisplayName -Alias $DL.Alias -RequireSenderAuthenticationEnabled $false -SubscriptionEnabled -AutoSubscribeNewMembers
for ($M = 0; $M -lt $Members.count;) {
try { Add-UnifiedGroupLinks -Identity $DL.Name -LinkType member -Links ($Members[$M]).DistinguishedName -EA stop -CF:$false } catch { $error[0] | FL * -F ;
Add-UnifiedGroupLinks -Identity $DL.Name -LinkType member -Links ($Members[$M]).DistinguishedName -CF:$false } ;$M++ ;
Write-Progress -Activity "Adding Member" -Id 2 -ParentId 1 -Status "Member: $(($Members[$M]).DisplayName)" -PercentComplete (($M/$Members.count)*100) }
#########################################################################################
############## Restart From CSV Only ####################################################
$RestoreMode = $false
IF ($RestoreMode) {
# DL Filedialog
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
InitialDirectory = [Environment]::GetFolderPath('MyDocuments')
Filter = 'CSV Files (*.CSV)|*.CSV' }
$null = $FileBrowser.ShowDialog()
$DL = Import-Csv $FileBrowser.FileName
#create new O365 Group with same Properties
New-UnifiedGroup -name $DL.Name -Alias $DL.Alias -PrimarySmtpAddress $DL.PrimarySmtpAddress -DisplayName $DL.DisplayName
Set-UnifiedGroup -Identity $DL.Name -DisplayName $DL.DisplayName -Alias $DL.Alias -RequireSenderAuthenticationEnabled $false -SubscriptionEnabled -AutoSubscribeNewMembers
# Members Filedialog
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
InitialDirectory = [Environment]::GetFolderPath('MyDocuments')
Filter = 'CSV Files (*.CSV)|*.CSV' }
$null = $FileBrowser.ShowDialog()
$Members = Import-Csv $FileBrowser.FileName
#ADD Members
for ($M = 0; $M -lt $Members.count;) {
try { Add-UnifiedGroupLinks -Identity $DL.Name -LinkType member -Links ($Members[$M]).DistinguishedName -EA stop -CF:$false } catch { $error[0] | FL * -F ;
Add-UnifiedGroupLinks -Identity $DL.Name -LinkType member -Links ($Members[$M]).DistinguishedName -EA stop -CF:$false } ;$M++ ;
Write-Progress -Activity "Adding Member" -Id 2 -ParentId 1 -Status "Member: $($Members[$M].DisplayName)" -PercentComplete (($M/$Members.count)*100) }
} # end
############## End / Restore ####################################################
#result
get-UnifiedGroup -Identity $DL.Name
(get-UnifiedGroupLinks -Identity $DL.Name -LinkType member).count
# Finished