-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathget-OULocation.ps1
88 lines (64 loc) · 3.36 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
87
88
<#
.SYNOPSIS
This function calculates the correct OU to place an object.
.DESCRIPTION
This function calculates the correct OU to place an object.
.PARAMETER originalDLConfiguration
The mail attribute of the group to search.
.OUTPUTS
Returns the organizational unit where the object should be stored.
.EXAMPLE
get-OULocation -originalDLConfiguration $originalDLConfiguration
#>
Function Get-OULocation
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
$originalDLConfiguration
)
#Output all parameters bound or unbound and their associated values.
write-functionParameters -keyArray $MyInvocation.MyCommand.Parameters.Keys -parameterArray $PSBoundParameters -variableArray (Get-Variable -Scope Local -ErrorAction Ignore)
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 $originalDLConfiguration.distinguishedname
$testOUSubstringLocation = $originalDLConfiguration.distinguishedName.indexof(",OU=")
out-logfile -string ("The location of ,OU= is:"+$testOUSubstringLocation)
if ($testOUSubStringLocation -ge 0)
{
out-logfile -string "The group is in an organizational unit."
out-logfile -string $testOUSubstringLocation.tostring()
$tempOUSubstring = $originalDLConfiguration.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 group is in a container and not an OU."
$testOUSubstringLocation = $originalDLConfiguration.distinguishedName.indexof(",CN=")
out-logfile -string $testOUSubstringLocation.tostring()
$tempOUSubstring = $originalDLConfiguration.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
}