-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShadow-Prelude3.ps1
78 lines (67 loc) · 1.93 KB
/
Shadow-Prelude3.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
function test-adpath {
[cmdletbinding()]
param (
[ValidateSet('OU','CN')]
[string]$type,
[string]$name,
[string]$path
)
Test-Path -Path "AD:\type=name,path"
}
function New-OU {
[cmdletbinding()]
param(
[string]$name,
[string]$description,
[string]$streetaddress,
[string]$pobox,
[string]$city,
[Alias('zipcode')]
[string]$postcode,
[Alias('province')]
[string]$state,
[string]$country
)
BEGIN {
if (-not $path){
$path = Get-ADDomain
Select -ExpandProperty DistinguishedName
}
}
PROCESS {
if (test-adpath -type OU -Name $name -path $path) {
throw "OU $name,$path already exists"
}
$sb = [system.test.stringbuilder]::new()
$vars = 'name', 'path', 'description', 'displayname', 'streetaddress',
'pobox', 'city', 'postcode', 'state', 'country'
foreach($var in $vars){
$v = Get-variable -Name $var -ErrorAction SilentlyContinue
if ($var -eq 'streetaddress'){
Write-Verbose -Message "`$var -eq 'streetaddress'"
if(($v.value).indexof("`n") -gt 0){
continue
}
}
if ($v.value){
$sline = "$((Get-Culture).TextInfo) = $($v.Value)"
[void]$sb.AppendLine($sline)
}
$topsplat = ConvertFrom-StringData -StringData $sb.toString()
if($topsplat['StreetAddress']){
New-AdOrganizationalUnit @topsplat
}
else{
New-AdorganizationalUnit $topsplat -StreetAddress $streetaddress
}
}
} # end PROCESS
<#
$stree = @'
Floor 3
1456 New Street
District 1
'@
New-OU -name test1 -description 'test one' -city London -streetaddress $street
#>
}