-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-OULocation.ps1
86 lines (62 loc) · 3.17 KB
/
get-OULocation.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
80
81
82
83
84
85
86
<#
.SYNOPSIS
This function calculates the correct OU to place an object.
.DESCRIPTION
This function calculates the correct OU to place an object.
.PARAMETER originalContactConfiguration
The mail attribute of the contact to search.
.OUTPUTS
Returns the organizational unit where the object should be stored.
.EXAMPLE
get-OULocation -originalContactConfiguration $originalContactConfiguration
#>
Function Get-OULocation
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
$originalContactConfiguration
)
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "BEGIN Get-OULocation"
Out-LogFile -string "********************************************************************************"
#Declare function variables.
[string]$returnOU=$NULL
#Test to see if the DN contains an OU.
out-logfile -string $originalContactConfiguration.distinguishedname
$testOUSubstringLocation = $originalContactConfiguration.distinguishedName.indexof(",OU=")
out-logfile -string ("The location of ,OU= is:"+$testOUSubstringLocation)
if ($testOUSubStringLocation -ge 0)
{
out-logfile -string "The contact is in an organizational unit."
out-logfile -string $testOUSubstringLocation.tostring()
$tempOUSubstring = $originalContactConfiguration.distinguishedname.substring($testOUSubstringLocation)
out-logfile -string "Temp OU Substring = "
out-logfile -string $tempOUSubstring
$testOUSubstringLocation = $tempOUSubstring.indexof("OU=")
out-logfile -string $testOUSubstringLocation.tostring()
$tempOUSubstring = $tempOUSubstring.substring($testOUSubstringLocation)
out-logfile -string "Temp OU Substring Substring ="
out-logfile -string $tempOUSubstring
}
else
{
out-logfile -string "The contact is in a container and not an OU."
$testOUSubstringLocation = $originalContactConfiguration.distinguishedName.indexof(",CN=")
out-logfile -string $testOUSubstringLocation.tostring()
$tempOUSubstring = $originalContactConfiguration.distinguishedname.substring($testOUSubstringLocation)
out-logfile -string "Temp OU Substring = "
out-logfile -string $tempOUSubstring
$testOUSubstringLocation = $tempOUSubstring.indexof("CN=")
out-logfile -string $testOUSubstringLocation.tostring()
$tempOUSubstring = $tempOUSubstring.substring($testOUSubstringLocation)
out-logfile -string "Temp OU Substring Substring ="
out-logfile -string $tempOUSubstring
}
$returnOU = $tempOUSubstring
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "END Get-OULocation"
Out-LogFile -string "********************************************************************************"
return $returnOU
}