Invoke-HostProfile
VMware: Applies a host profile to the specified host or cluster
#Requires -Version 5.1
#Requires -Modules VMware.VimAutomation.Core
[CmdletBinding(DefaultParameterSetName = "Host")]
Param(
[Parameter(Mandatory = $true, ParameterSetName = "Host")]
[Parameter(Mandatory = $true, ParameterSetName = "Cluster")]
[string]$VIServer,
[Parameter(Mandatory = $true, ParameterSetName = "Host")]
[Parameter(Mandatory = $true, ParameterSetName = "Cluster")]
[pscredential]$VICredential,
[Parameter(Mandatory = $true, ParameterSetName = "Host")]
[Parameter(Mandatory = $true, ParameterSetName = "Cluster")]
[string]$ProfileName,
[Parameter(Mandatory = $true, ParameterSetName = "Host")]
[string]$HostName,
[Parameter(Mandatory = $true, ParameterSetName = "Cluster")]
[string]$ClusterName,
[Parameter(ParameterSetName = "Host")]
[Parameter(ParameterSetName = "Cluster")]
[switch]$ApplyOnly,
[Parameter(ParameterSetName = "Host")]
[Parameter(ParameterSetName = "Cluster")]
[switch]$AssociateOnly
)
Process {
$vmServer = $null
try {
$vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$profile = Get-VMHostProfile -Name $ProfileName -Server $vmServer -ErrorAction Stop
if ($PSCmdlet.ParameterSetName -eq "Host") {
$entity = Get-VMHost -Server $vmServer -Name $HostName -ErrorAction Stop
}
else {
$entity = Get-Cluster -Server $vmServer -Name $ClusterName -ErrorAction Stop
}
$null = Invoke-VMHostProfile -Entity $entity -Profile $profile -AssociateOnly:$AssociateOnly -ApplyOnly:$ApplyOnly -Server $vmServer -Confirm:$false -ErrorAction Stop
if ($PSCmdlet.ParameterSetName -eq "Host") {
$result = Get-VMHost -Server $vmServer -Name $HostName -ErrorAction Stop | Select-Object *
}
else {
$result = Get-Cluster -Server $vmServer -Name $ClusterName -ErrorAction Stop | Select-Object *
}
foreach ($item in $result) {
$item | Add-Member -NotePropertyName 'Timestamp' -NotePropertyValue $timestamp -Force
Write-Output $item
}
}
catch { throw }
finally { if ($null -ne $vmServer) { Disconnect-VIServer -Server $vmServer -Force -Confirm:$false -ErrorAction SilentlyContinue } }
}IP address or DNS name of the vSphere server
PSCredential object for authenticating with the server
Host profile to apply
Host to apply the host profile to
Cluster to apply the host profile to
Off
Apply the host profile without associating it
Off
Associate the host profile without applying it