-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove-toNonSyncOU.ps1
74 lines (51 loc) · 2.01 KB
/
move-toNonSyncOU.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
<#
.SYNOPSIS
This function moves the contact to the non-SYNC OU. This is necessary to process the contact deletion from Office 365.
.DESCRIPTION
This function moves the contact to the non-SYNC OU. This is necessary to process the contact deletion from Office 365.
.PARAMETER GlobalCatalogServer
The global catalog to make the query against.
.PARAMETER DN
The original DN of the object.
.PARAMETER OU
This is the OU that is set to not synchonize in AD Connect.
.OUTPUTS
None
.EXAMPLE
move-toNonSyncOU -globalCatalogServer GC -OU NonSyncOU -DN contactDN
#>
Function move-toNonSyncOU
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
[string]$globalCatalogServer,
[Parameter(Mandatory = $true)]
$OU,
[Parameter(Mandatory = $true)]
$DN,
[Parameter(Mandatory = $true)]
$adCredential
)
#Declare function variables.
#Start function processing.
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "START MOVE-TONONSYNCOU"
Out-LogFile -string "********************************************************************************"
#Log the parameters and variables for the function.
Out-LogFile -string ("GlobalCatalogServer = "+$globalCatalogServer)
out-logfile -string ("DN = "+$dn)
out-logfile -string ("OU = "+$OU)
try
{
Out-LogFile -string "Move the contact to the non-SYNC OU..."
move-adObject -identity $DN -targetPath $OU -credential $adCredential -server $globalCatalogServer
}
catch
{
Out-LogFile -string $_ -isError:$TRUE
}
Out-LogFile -string "END MOVE-TONONSYNCOU"
Out-LogFile -string "********************************************************************************"
}