-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathNew-VMHVOSCustomizationSpec.ps1
206 lines (176 loc) · 7.13 KB
/
New-VMHVOSCustomizationSpec.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#Requires -Version 5.0
#Requires -Modules VMware.VimAutomation.Core
<#
.SYNOPSIS
Creates a new OS customization specifications
.DESCRIPTION
.NOTES
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
the use and the consequences of the use of this freely available script.
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
© ScriptRunner Software GmbH
.COMPONENT
Requires Module VMware.VimAutomation.Core
.LINK
https://github.com/scriptrunner/ActionPacks/tree/master/VMware/Specifications
.Parameter VIServer
[sr-en] IP address or the DNS name of the vSphere server to which you want to connect
[sr-de] IP Adresse oder Name des vSphere Servers
.Parameter VICredential
[sr-en] PSCredential object that contains credentials for authenticating with the server
[sr-de] Benutzerkonto um diese Aktion durchzuführen
.Parameter SpecName
[sr-en] Name for new the OS customization specification
[sr-de] Name der neuen Spezifikation
.Parameter AdminPassword
[sr-en] The new OS administrator's password
[sr-de] Neues Administrator Kennwort
.Parameter AutoLogonCount
[sr-en] Number of times the virtual machine should automatically login as an administrator
[sr-de] Anzahl wie oft sich die virtuelle Maschine automatisch als Administrator anmelden soll
.Parameter DeleteAccounts
[sr-en] Delete all user accounts
[sr-de] Alle Benutzerkonten löschen
.Parameter Description
[sr-en] New description for the specification
[sr-de] Neue Beschreibung der Spezifikation
.Parameter DNSServer
[sr-en] DNS server
[sr-de] DNS Server
.Parameter Domain
[sr-en] Domain name
[sr-de] Domänenname
.Parameter DomainCredentials
[sr-en] Credential for authentication with the specified domain
[sr-de] Benutzerkonto für die Authentifizierung mit der angegebenen Domäne
.Parameter DomainUsername
[sr-en] Username for authentication with the specified domain
[sr-de] Benutzername für die Authentifizierung mit der angegebenen Domäne
.Parameter DomainPassword
[sr-en] Password for authentication with the specified domain
[sr-de] Kennwort für die Authentifizierung mit der angegebenen Domäne
.Parameter AdminFullName
[sr-en] Administrator's full name
[sr-de] Voller Name des Administrators
.Parameter NamingScheme
[sr-en] Naming scheme for the virtual machine
[sr-de] Namensschema der VM
.Parameter OrgName
[sr-en] Name of the organization to which the administrator belongs
[sr-de] Name der Organisation, zu der der Administrator gehört
.Parameter ProductKey
[sr-en] MS product key
[sr-de] MS Produkt-Schlüssel
.Parameter SpecificationType
[sr-en] Type of the OS customization specifications
[sr-de] Typ der Spezifikationen
.Parameter TimeZone
[sr-en] Name of the time zone for a Windows guest OS
[sr-de] name der Zeitzone für das Windows OS
.Parameter Workgroup
[sr-en] Workgroup, applies only to Windows operating systems
[sr-de] Workgroup, betrifft nur für Windows-Betriebssysteme
#>
[CmdLetBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$VIServer,
[Parameter(Mandatory = $true)]
[pscredential]$VICredential,
[Parameter(Mandatory = $true)]
[string]$SpecName,
[Parameter(Mandatory = $true)]
[string]$AdminFullName,
[Parameter(Mandatory = $true)]
[string]$OrgName,
[string]$Description,
[bool]$DeleteAccounts,
[int]$AutoLogonCount,
[string]$DNSServer,
[string]$AdminPassword,
[ValidateSet("Custom","Fixed","Prefix","Vm")]
[string]$NamingScheme,
[string]$ProductKey,
[ValidateSet("Persistent","NonPersistent")]
[string]$SpecificationType,
[string]$Domain,
[pscredential]$DomainCredentials,
[string]$DomainUsername,
[string]$DomainPassword,
[ValidateSet('W. Europe','E. Europe','Central Europe','Central European','Central (U.S. and Canada)','Central America','Eastern (U.S. and Canada)','GMT (Greenwich Mean Time)','GMT Greenwich','EET (Athens, Istanbul, Minsk)','EET (Helsinki, Riga, Tallinn)')]
[string]$TimeZone,
[string]$Workgroup
)
Import-Module VMware.VimAutomation.Core
try{
[string[]]$Properties = @('Name','Type','Server','LastUpdate','DomainAdminUsername','DomainUsername','Description','Domain','FullName','OSType','LicenseMode','LicenseMaxConnections','Id')
$Script:vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
'Server' = $Script:vmServer
'Confirm' = $false
'FullName' = $AdminFullName
'OrgName' = $OrgName
}
If($PSBoundParameters.ContainsKey('SpecName') -eq $true){
$cmdArgs.Add('Name',$SpecName)
}
If($PSBoundParameters.ContainsKey('AutoLogonCount') -eq $true){
$cmdArgs.Add('AutoLogonCount',$AutoLogonCount)
}
If($PSBoundParameters.ContainsKey('AdminPassword') -eq $true){
$cmdArgs.Add('AdminPassword',$AdminPassword)
}
If($PSBoundParameters.ContainsKey('DeleteAccounts') -eq $true){
$cmdArgs.Add('DeleteAccounts',$DeleteAccounts)
}
If($PSBoundParameters.ContainsKey('Description') -eq $true){
$cmdArgs.Add('Description',$Description)
}
If($PSBoundParameters.ContainsKey('DNSServer') -eq $true){
$cmdArgs.Add('DNSServer',$DNSServer)
}
If($PSBoundParameters.ContainsKey('Domain') -eq $true){
$cmdArgs.Add('Domain',$Domain)
}
If($PSBoundParameters.ContainsKey('DomainUsername') -eq $true){
$cmdArgs.Add('DomainUsername',$DomainUsername)
}
If($PSBoundParameters.ContainsKey('DomainPassword') -eq $true){
$cmdArgs.Add('DomainPassword',$DomainPassword)
}
If($PSBoundParameters.ContainsKey('DomainCredentials') -eq $true){
$cmdArgs.Add('DomainCredentials',$DomainCredentials)
}
If($PSBoundParameters.ContainsKey('NamingScheme') -eq $true){
$cmdArgs.Add('NamingScheme',$NamingScheme)
}
If($PSBoundParameters.ContainsKey('ProductKey') -eq $true){
$cmdArgs.Add('ProductKey',$ProductKey)
}
If($PSBoundParameters.ContainsKey('TimeZone') -eq $true){
$cmdArgs.Add('TimeZone',$TimeZone)
}
If($PSBoundParameters.ContainsKey('SpecificationType') -eq $true){
$cmdArgs.Add('Type',$SpecificationType)
}
If($PSBoundParameters.ContainsKey('Workgroup') -eq $true){
$cmdArgs.Add('Workgroup',$Workgroup)
}
$output = New-OSCustomizationSpec @cmdArgs | Select-Object $Properties
if($SRXEnv) {
$SRXEnv.ResultMessage = $output
}
else{
Write-Output $output
}
}
catch{
throw
}
finally{
if($null -ne $Script:vmServer){
Disconnect-VIServer -Server $Script:vmServer -Force -Confirm:$false
}
}