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+ }
0 commit comments