Skip to content

Commit dd1eb2a

Browse files
VMware host patch scripts
1 parent 6d1ad2d commit dd1eb2a

8 files changed

Lines changed: 325 additions & 10 deletions

File tree

VMware/Host/Get-VMHVHostPatch.ps1

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#Requires -Version 5.0
2+
#Requires -Modules VMware.VimAutomation.Core
3+
4+
<#
5+
.SYNOPSIS
6+
Retrieves the host patches installed on the specified host
7+
8+
.DESCRIPTION
9+
10+
.NOTES
11+
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
12+
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
13+
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
14+
the use and the consequences of the use of this freely available script.
15+
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
16+
© ScriptRunner Software GmbH
17+
18+
.COMPONENT
19+
Requires Module VMware.VimAutomation.Core
20+
21+
.LINK
22+
https://github.com/scriptrunner/ActionPacks/tree/master/VMware/Host
23+
24+
.Parameter VIServer
25+
[sr-en] IP address or the DNS name of the vSphere server to which you want to connect
26+
[sr-de] IP Adresse oder Name des vSphere Servers
27+
28+
.Parameter VICredential
29+
[sr-en] PSCredential object that contains credentials for authenticating with the server
30+
[sr-de] Benutzerkonto um diese Aktion durchzuführen
31+
32+
.Parameter HostName
33+
[sr-en] Name of the host you want to retrieve patches
34+
[sr-de] Hostname
35+
36+
.Parameter Properties
37+
[sr-en] List of properties to expand. Use * for all properties
38+
[sr-de] Liste der zu anzuzeigenden Eigenschaften. Verwenden Sie * für alle Eigenschaften
39+
#>
40+
41+
[CmdLetBinding()]
42+
Param(
43+
[Parameter(Mandatory = $true)]
44+
[string]$VIServer,
45+
[Parameter(Mandatory = $true)]
46+
[pscredential]$VICredential,
47+
[Parameter(Mandatory = $true)]
48+
[string]$HostName,
49+
[ValidateSet('*','Name','InstallDate','AcceptanceLevel','CreationDate','ID','Status','Vendor','Version')]
50+
[string[]]$Properties = @('Name','InstallDate','AcceptanceLevel','CreationDate','ID','Status','Vendor','Version')
51+
)
52+
53+
Import-Module VMware.VimAutomation.Core
54+
55+
try{
56+
if($Properties -contains '*'){
57+
$Properties = @('*')
58+
}
59+
$Script:vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
60+
61+
$vmHost = Get-VMHost -Server $vmServer -Name $HostName -ErrorAction Stop
62+
$result = (Get-ESXCli -VMHost $vmHost).software.vib.list() | Select-Object $Properties
63+
64+
if($SRXEnv) {
65+
$SRXEnv.ResultMessage = $result
66+
}
67+
else{
68+
Write-Output $result
69+
}
70+
}
71+
catch{
72+
throw
73+
}
74+
finally{
75+
if($null -ne $Script:vmServer){
76+
Disconnect-VIServer -Server $Script:vmServer -Force -Confirm:$false
77+
}
78+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#Requires -Version 5.0
2+
#Requires -Modules VMware.VimAutomation.Core
3+
4+
<#
5+
.SYNOPSIS
6+
Updates the specified host
7+
8+
.DESCRIPTION
9+
10+
.NOTES
11+
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
12+
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
13+
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
14+
the use and the consequences of the use of this freely available script.
15+
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
16+
© ScriptRunner Software GmbH
17+
18+
.COMPONENT
19+
Requires Module VMware.VimAutomation.Core
20+
21+
.LINK
22+
https://github.com/scriptrunner/ActionPacks/tree/master/VMware/Host
23+
24+
.Parameter VIServer
25+
[sr-en] IP address or the DNS name of the vSphere server to which you want to connect
26+
[sr-de] IP Adresse oder Name des vSphere Servers
27+
28+
.Parameter VICredential
29+
[sr-en] PSCredential object that contains credentials for authenticating with the server
30+
[sr-de] Benutzerkonto um diese Aktion durchzuführen
31+
32+
.Parameter HostName
33+
[sr-en] Name of the host you want to retrieve patches
34+
[sr-de] Hostname
35+
36+
.Parameter HostCredential
37+
[sr-en] PSCredential object that contains credentials for authenticating with the host
38+
[sr-de] Benutzerkonto zur Hostauthentifizierung
39+
40+
.Parameter HostUsername
41+
[sr-en] User name for authenticating with the host
42+
[sr-de] Benutzername zur Hostauthentifizierung
43+
44+
.Parameter HostPassword
45+
[sr-en] Password for authenticating with the host
46+
[sr-de] Kennwort zur Hostauthentifizierung
47+
48+
.Parameter WebPath
49+
[sr-en] Web location of the patches
50+
[sr-de] Webadresse der Patchs
51+
52+
.Parameter HostPath
53+
[sr-en] File path on the ESX/ESXi host to the patches
54+
[sr-de] Pfad der Patchs auf dem ESX/ESXi Host
55+
56+
.Parameter LocalPath
57+
[sr-en] Local file system path to the patches
58+
[sr-de] Pfad der Patchs
59+
60+
.Parameter RunAsync
61+
[sr-en] Indicates that the command returns immediately without waiting for the task to complete
62+
[sr-de] Asynchrone Ausführung
63+
#>
64+
65+
[CmdLetBinding()]
66+
Param(
67+
[Parameter(Mandatory = $true,ParameterSetName = "HostPath")]
68+
[Parameter(Mandatory = $true,ParameterSetName = "WebPath")]
69+
[Parameter(Mandatory = $true,ParameterSetName = "LocalPath")]
70+
[string]$VIServer,
71+
[Parameter(Mandatory = $true,ParameterSetName = "HostPath")]
72+
[Parameter(Mandatory = $true,ParameterSetName = "WebPath")]
73+
[Parameter(Mandatory = $true,ParameterSetName = "LocalPath")]
74+
[pscredential]$VICredential,
75+
[Parameter(Mandatory = $true,ParameterSetName = "HostPath")]
76+
[Parameter(Mandatory = $true,ParameterSetName = "WebPath")]
77+
[Parameter(Mandatory = $true,ParameterSetName = "LocalPath")]
78+
[string]$HostName,
79+
[Parameter(Mandatory = $true,ParameterSetName = "HostPath")]
80+
[string]$HostPath,
81+
[Parameter(Mandatory = $true,ParameterSetName = "WebPath")]
82+
[string]$WebPath,
83+
[Parameter(Mandatory = $true,ParameterSetName = "LocalPath")]
84+
[string]$LocalPath,
85+
[Parameter(ParameterSetName = "LocalPath")]
86+
[pscredential]$HostCredential,
87+
[Parameter(ParameterSetName = "LocalPath")]
88+
[string]$HostUsername,
89+
[Parameter(ParameterSetName = "LocalPath")]
90+
[securestring]$HostPassword,
91+
[Parameter(ParameterSetName = "HostPath")]
92+
[Parameter(ParameterSetName = "WebPath")]
93+
[Parameter(ParameterSetName = "LocalPath")]
94+
[switch]$RunAsync
95+
)
96+
97+
Import-Module VMware.VimAutomation.Core
98+
99+
try{
100+
$Script:result = $null
101+
$Script:vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
102+
103+
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
104+
'Server' = $Script:vmServer
105+
}
106+
$vmHost = Get-VMHost @cmdArgs -Name $HostName
107+
108+
$cmdArgs.Add('RunAsync', $null)
109+
$cmdArgs.Add('Confirm', $false)
110+
$cmdArgs.Add('VMHost', $vmHost)
111+
if($PSCmdlet.ParameterSetName -eq 'LocalPath'){
112+
if($PSBoundParameters.ContainsKey('HostCredential') -eq $true){
113+
$cmdArgs.Add('HostCredential', $HostCredential)
114+
}
115+
else{
116+
if($PSBoundParameters.ContainsKey('HostUsername') -eq $true){
117+
$cmdArgs.Add('HostUsername', $HostUsername)
118+
}
119+
if($PSBoundParameters.ContainsKey('HostPassword') -eq $true){
120+
$cmdArgs.Add('HostPassword', $HostPassword)
121+
}
122+
}
123+
$Script:result = Install-VMHostPatch @cmdArgs -LocalPath $LocalPath
124+
}
125+
elseif($PSCmdlet.ParameterSetName -eq 'WebPath'){
126+
$Script:result = Install-VMHostPatch @cmdArgs -WebPath $WebPath
127+
}
128+
else{
129+
$Script:result = Install-VMHostPatch @cmdArgs -HostPath $HostPath
130+
}
131+
132+
if($SRXEnv) {
133+
$SRXEnv.ResultMessage = $Script:result
134+
}
135+
else{
136+
Write-Output $Script:result
137+
}
138+
}
139+
catch{
140+
throw
141+
}
142+
finally{
143+
if($null -ne $Script:vmServer){
144+
Disconnect-VIServer -Server $Script:vmServer -Force -Confirm:$false
145+
}
146+
}

VMware/Host/readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363

6464
Retrieves the host network adapters on a vCenter Server system
6565

66+
+ [Get-VMHVHostPatch.ps1](./Get-VMHVHostPatch.ps1)
67+
68+
Retrieves the host patches installed on the specified host
69+
6670
+ [Get-VMHVHostPCIDevice.ps1](./Get-VMHVHostPCIDevice.ps1)
6771

6872
Retrieves the PCI devices on the specified hosts
@@ -87,6 +91,10 @@
8791

8892
Imports a host profile from a file
8993

94+
+ [Install-VMHVHostPatch.ps1](./Install-VMHVHostPatch.ps1)
95+
96+
Updates the specified host
97+
9098
+ [Invoke-VMHVHostCommand.ps1](./Invoke-VMHVHostCommand.ps1)
9199

92100
Invokes a command for the specified host.<br>

VMware/VMs/New-VMHVVirtualMachine.ps1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Version 5.0
1+
#Requires -Version 5.0
22
# Requires -Modules VMware.PowerCLI
33

44
<#
@@ -124,7 +124,6 @@ Param(
124124
[ValidateSet("e1000","Flexible","Vmxnet","EnhancedVmxnet","Vmxnet3")]
125125
[string]$NetworkAdapterType = "e1000",
126126
[string]$GuestId,
127-
[ValidateSet("NonPersistent","Persistent")]
128127
[string]$OSCustomizationSpec,
129128
[string]$HardwareVersion,
130129
[string]$Location,
@@ -167,13 +166,15 @@ try{
167166
$folder = Get-Folder -Server $Script:vmServer -Name $Location -ErrorAction Stop
168167
$cmdArgs.Add('Location' ,$Folder)
169168
}
169+
if($PSBoundParameters.ContainsKey('OSCustomizationSpec') -eq $true){
170+
$spec = Get-OSCustomizationSpec -Name $OSCustomizationSpec -Server $Script:vmServer
171+
$cmdArgs.Add('OSCustomizationSpec' ,$spec)
172+
}
170173
$Script:machine = New-VM @cmdArgs
174+
171175
if($PSBoundParameters.ContainsKey('GuestId') -eq $true){
172176
$null = Set-VM -Server $Script:vmServer -VM $Script:machine -GuestId $GuestId -Confirm:$False -ErrorAction Stop
173177
}
174-
if($PSBoundParameters.ContainsKey('OSCustomizationSpec') -eq $true){
175-
$null = Set-VM -Server $Script:vmServer -VM $Script:machine -OSCustomizationSpec $OSCustomizationSpec -Confirm:$False -ErrorAction Stop
176-
}
177178
if($PSBoundParameters.ContainsKey('HardwareVersion') -eq $true){
178179
$null = Set-VM -Server $Script:vmServer -VM $Script:machine -HardwareVersion $HardwareVersion -Confirm:$False -ErrorAction Stop
179180
}

VMware/VMs/Set-VMHVVirtualMachine.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Requires -Version 4.0
1+
#Requires -Version 4.0
22
# Requires -Modules VMware.PowerCLI
33

44
<#
@@ -52,7 +52,10 @@
5252
Specifies the guest operating system
5353
5454
.Parameter OSCustomizationSpec
55-
Specifies a customization specification that is to be applied to the virtual machine
55+
[sr-en] Customization specification that is to be applied to the virtual machine.
56+
This works only in 32-bit mode
57+
[sr-de] Benutzerdefinierte Einstellungen der virtuellen Maschine
58+
Nur für 32Bit
5659
5760
.Parameter HardwareVersion
5861
Specifies the version to which you want to upgrade the virtual machine.
@@ -97,7 +100,6 @@ Param(
97100
[string]$GuestId,
98101
[Parameter(ParameterSetName = "byID")]
99102
[Parameter(ParameterSetName = "byName")]
100-
[ValidateSet("NonPersistent","Persistent")]
101103
[string]$OSCustomizationSpec,
102104
[Parameter(ParameterSetName = "byID")]
103105
[Parameter(ParameterSetName = "byName")]
@@ -140,7 +142,8 @@ try{
140142
$null = Set-VM -Server $Script:vmServer -VM $Script:machine -GuestId $GuestId -Confirm:$False -ErrorAction Stop
141143
}
142144
if($PSBoundParameters.ContainsKey('OSCustomizationSpec') -eq $true){
143-
$null = Set-VM -Server $Script:vmServer -VM $Script:machine -OSCustomizationSpec $OSCustomizationSpec -Confirm:$False -ErrorAction Stop
145+
$spec = Get-OSCustomizationSpec -Name $OSCustomizationSpec -Server $Script:vmServer
146+
$null = Set-VM -Server $Script:vmServer -VM $Script:machine -OSCustomizationSpec $spec -Confirm:$False -ErrorAction Stop
144147
}
145148
if($PSBoundParameters.ContainsKey('HardwareVersion') -eq $true){
146149
$null = Set-VM -Server $Script:vmServer -VM $Script:machine -HardwareVersion $HardwareVersion -Confirm:$False -ErrorAction Stop
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#Requires -Version 5.0
2+
#Requires -Modules VMware.VimAutomation.Core
3+
4+
<#
5+
.SYNOPSIS
6+
Creates a report with the host patches installed on the specified host
7+
8+
.DESCRIPTION
9+
10+
.NOTES
11+
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
12+
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
13+
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
14+
the use and the consequences of the use of this freely available script.
15+
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
16+
© ScriptRunner Software GmbH
17+
18+
.COMPONENT
19+
Requires Module VMware.VimAutomation.Core
20+
21+
.LINK
22+
https://github.com/scriptrunner/ActionPacks/tree/master/VMware/Host
23+
24+
.Parameter VIServer
25+
[sr-en] IP address or the DNS name of the vSphere server to which you want to connect
26+
[sr-de] IP Adresse oder Name des vSphere Servers
27+
28+
.Parameter VICredential
29+
[sr-en] PSCredential object that contains credentials for authenticating with the server
30+
[sr-de] Benutzerkonto um diese Aktion durchzuführen
31+
32+
.Parameter HostName
33+
[sr-en] Name of the host you want to retrieve patches
34+
[sr-de] Hostname
35+
#>
36+
37+
[CmdLetBinding()]
38+
Param(
39+
[Parameter(Mandatory = $true)]
40+
[string]$VIServer,
41+
[Parameter(Mandatory = $true)]
42+
[pscredential]$VICredential,
43+
[Parameter(Mandatory = $true)]
44+
[string]$HostName
45+
)
46+
47+
Import-Module VMware.VimAutomation.Core
48+
49+
try{
50+
[string[]]$Properties = @('Name','InstallDate','AcceptanceLevel','CreationDate','ID','Status','Vendor','Version')
51+
$Script:vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
52+
53+
$vmHost = Get-VMHost -Server $vmServer -Name $HostName -ErrorAction Stop
54+
$result = (Get-ESXCli -VMHost $vmHost).software.vib.list() | Select-Object $Properties
55+
56+
if (Get-Command 'ConvertTo-ResultHtml' -ErrorAction SilentlyContinue) {
57+
ConvertTo-ResultHtml -Result $result
58+
}
59+
if($SRXEnv) {
60+
$SRXEnv.ResultMessage = $result
61+
}
62+
else{
63+
Write-Output $result
64+
}
65+
}
66+
catch{
67+
throw
68+
}
69+
finally{
70+
if($null -ne $Script:vmServer){
71+
Disconnect-VIServer -Server $Script:vmServer -Force -Confirm:$false
72+
}
73+
}

0 commit comments

Comments
 (0)