Public/New-bConnectOrgUnitExtension.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Function New-bConnectOrgUnitExtension() {
    <#
        .Synopsis
            Creates a new Extension for OrgUnits.
            Empty or filled with given information.
        .Parameter DIP
            Valid DIP or list of DIPs (separated by ";").
        .Parameter Domain
            Valid Windows Domain Name.
        .Parameter LocalAdminPassword
            Local admin password for OU (set during OS-Install)
            Must be encrypted with baramundi Cryptor
        .Parameter EnableDHCP
        .Parameter SubnetMask
        .Parameter DefaultGateway
        .Parameter DnsServer
        .Parameter DnsServer2
        .Parameter DnsDomain
        .Parameter WinsServer
        .Parameter WinsServer2
        .Parameter AutoInstallJobs
            Array of valid Job-GUIDs
        .Parameter HardwareProfiles
            Array of valid HardwareProfile-GUIDs
        .Parameter InheritAutoInstallJobs
            Array of valid inherited Job-GUIDs
        .Parameter RequestableJobs
            Array of valid Job-GUIDs
        .Outputs
            Array of OrgUnit extension (see bConnect documentation for more details)
    #>


    Param(
        [string]$DIP = "",
        [string]$Domain = "",
        [SecureString]$LocalAdminPassword = "",
        [switch]$EnableDHCP = $true,
        [string]$SubnetMask = "",
        [string]$DefaultGateway = "",
        [string]$DnsServer = "",
        [string]$DnsServer2 = "",
        [string]$DnsDomain = "",
        [string]$WinsServer = "",
        [string]$WinsServer2 = "",
        [string[]]$AutoInstallJobs = @(),
        [string[]]$HardwareProfiles = @(),
        [switch]$InheritAutoInstallJobs = $true,
        [string[]]$RequestableJobs = @()
    )

    If($EnableDHCP) {
        $_enabledhcp = $true
    } else {
        $_enabledhcp = $false
    }

    If($InheritAutoInstallJobs) {
        $_inheritAutoInstallJobs = $true
    } else {
        $_inheritAutoInstallJobs = $false
    }

    $_autoInstallJobs = @()
    Foreach($aiJob in $AutoInstallJobs) {
        If(Test-Guid -Guid $aiJob) {
            $_autoInstallJobs += $aiJob
        } else {
            $_job = Search-bConnectJob -Term $aiJob
            $_autoInstallJobs += $_job.Id
        }
    }

    $_requestableJobs = @()
    Foreach($rJob in $RequestableJobs) {
        If(Test-Guid -Guid $rJob) {
            $_requestableJobs += $rJob
        } else {
            $_job = Search-bConnectJob -Term $rJob
            $_requestableJobs += $_job.Id
        }
    }

    $_new_extension = @{
        DIP = $DIP;
        Domain = $Domain;
        LocalAdminPassword = $LocalAdminPassword;
        EnableDHCP = $_enabledhcp;
        SubnetMask = $SubnetMask;
        DefaultGateway = $DefaultGateway;
        DnsServer = $DnsServer;
        DnsServer2 = $DnsServer2;
        DnsDomain = $DnsDomain;
        WinsServer = $WinsServer;
        WinsServer2 = $WinsServer2;
        AutoInstallJobs = $_autoInstallJobs;
        HardwareProfiles = $HardwareProfiles;
        InheritAutoInstallJobs = $_inheritAutoInstallJobs;
        RequestableJobs = $_requestableJobs;
    }

    return $_new_extension
}