-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathremove-o365CloudOnlyGroup.ps1
79 lines (57 loc) · 2.8 KB
/
remove-o365CloudOnlyGroup.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
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
<#
.SYNOPSIS
This function disabled the on premies distribution list - removing it from azure ad and exchange online.
.DESCRIPTION
This function disabled the on premies distribution list - removing it from azure ad and exchange online.
.PARAMETER parameterSet
These are the parameters that will be manually cleared from the object in AD mode.
.PARAMETER DN
The DN of the group to remove.
.PARAMETER GlobalCatalog
The global catalog server the operation should be performed on.
.PARAMETER UseExchange
If set to true disablement will occur using the exchange on premises powershell commands.
.OUTPUTS
No return.
.EXAMPLE
Disable-OriginalDL -originalDLConfiguration $configuration -globalCatalogServer $GC -parameterSet $parameterArray -adCredential $cred
#>
Function remove-o365CloudOnlyGroup
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
$office365DLConfiguration,
[Parameter(Mandatory = $false)]
$DLCleanupRequired=$false
)
#Output all parameters bound or unbound and their associated values.
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "BEGIN remove-o365CloudOnlyGroup"
Out-LogFile -string "********************************************************************************"
write-functionParameters -keyArray $MyInvocation.MyCommand.Parameters.Keys -parameterArray $PSBoundParameters -variableArray (Get-Variable -Scope Local -ErrorAction Ignore)
if ($DLCleanupRequired -eq $FALSE)
{
try{
remove-o365DistributionGroup -identity $office365DLConfiguration.externalDirectoryObjectID -confirm:$FALSE -BypassSecurityGroupManagerCheck -errorAction STOP
}
catch{
out-logfile -string "Error removing the original distribution list from Office 365."
out-logfile -string $_ -isError:$TRUE
}
}
else
{
try{
remove-o365DistributionGroup -identity $office365DLConfiguration.externalDirectoryObjectID -confirm:$FALSE -BypassSecurityGroupManagerCheck -errorAction STOP
}
catch{
out-logfile -string "Error removing the original distribution list from Office 365 - not failing is optional cleanup operation."
out-logfile -string $_
}
}
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "END remove-o365CloudOnlyGroup"
Out-LogFile -string "********************************************************************************"
}