Remediating inventory objects

To remediate inventory objects against specified baselines, you can use the Update-Entity cmdlet. The syntax of the Update-Entity cmdlet is as follows:

Update-Entity [-Server <VIServer[]>] -Entity <InventoryItem> -Baseline <Baseline[]> [-ExcludePatch <Patch[]>] [-GuestCreateSnapshot [<Boolean>]] [-GuestKeepSnapshotHours <Int32>] [-GuestTakeMemoryDump [<Boolean>]] [-GuestSnapshotName <String>] [-GuestSnapshotDescription <String>] [-HostRetryDelaySeconds <Int32>] [-HostNumberOfRetries <Int32>] [-HostFailureAction <HostRemediationFailureAction>] [-HostPreRemediationPowerAction <HostPreRemediationPowerAction>] [-HostDisableMediaDevices [<Boolean>]] [-HostIgnoreThirdPartyDrivers [<Boolean>]] [-HostEnablePXEbootHostPatching [<Boolean>]] [-ClusterDisableDistributedPowerManagement [<Boolean>]] [-ClusterDisableHighAvailability [<Boolean>]] [-ClusterDisableFaultTolerance [<Boolean>]] [-ClusterEnableParallelRemediation [<Boolean>]] [-RunAsync] [-WhatIf] [-Confirm] [<CommonParameters>]

The -Entity, and -Baseline parameters are required. The other parameters are to specify options for the remediation, such as patches to exclude from the remediation, options for the creation of snapshots during the remediation of virtual machines, the number of retries, and running the command in asynchronous mode, so it will return immediately without waiting for the task to complete.

Tip

You can specify multiple baselines as the value of the -Baseline parameter. However, you can specify only one entity as the value of the -Entity parameter.

In the upcoming sections Upgrading or patching ESXi hosts, Updating VMware Tools, and Upgrading virtual machine hardware, we will demonstrate the Update-Entity cmdlet in different use cases.

Upgrading or patching ESXi hosts

Before you can upgrade your ESXi hosts to a new version or install patches to ESXi hosts, you have to attach the baselines you want to use, to the hosts. In the preceding section, Attaching baselines to inventory objects , you learned how to do this.

In the following example, we will install the critical and noncritical host patches from the baselines Critical Host Patches (Predefined) and Non-Critical Host Patches (Predefined) on all of the ESXi hosts in Cluster01. During the remediation process, Distributed Power Management, Fault Tolerance, and High Availability will be disabled on the cluster. The remediation process will update hosts in parallel mode. Hosts with preinstalled third-party drivers will also be remediated.

PowerCLI C:> $Cluster = Get-Cluster -Name Cluster01
PowerCLI C:> $Baseline = Get-Baseline -Name 'Critical Host
    Patches (Predefined)','Non-Critical Host Patches (Predefined)'
PowerCLI C:> Update-Entity -Entity $Cluster -Baseline $Baseline
    -Confirm:$false -ClusterDisableDistributedPowerManagement:$true
    -ClusterDisableFaultTolerance:$true -ClusterDisableHighAvailability:
    $true -ClusterEnableParallelRemediation:$true -
    HostIgnoreThirdPartyDrivers:$true

The preceding commands do not return any output.

Tip

You might receive an error message: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. This will not mean that the upgrade or patching was unsuccessful. The upgrade or patching just took too long to keep the connection open.

Toolspdating VMware Tools

In Chapter 5, Managing Virtual Machines with PowerCLI, you already learned how to update the VMware Tools using the Update-Tools cmdlet. In PowerCLI there are more ways to perform a VMware Tools update. In this section, we will use the Update-Entity cmdlet to do this. To update one or more virtual machines, you have to use the VMware Tools Upgrade to Match Host (Predefined) baseline. As the value of the -Entity parameter, you have to specify the virtual machine or template that you want to update, or a container object such as a folder or data center, containing the virtual machines or templates, you want to update.

In the following example, we will update the VMware Tools on all virtual machines in the data center New York. Before the update, we will create a snapshot of the virtual machines. In case something goes wrong during the update, you can go back to the snapshot.

Tip

Remember to remove the snapshots after successful remediation.

If you want the snapshots to be deleted automatically, you can use the -GuestKeepSnapshotHours parameter and specify the number of hours you want to keep the snapshots, as a value. We have the following code:

PowerCLI C:> $Datacenter = Get-Datacenter -Name 'New York'
PowerCLI C:> $Baseline = Get-Baseline -Name 'VMware Tools 
    Upgrade to Match Host (Predefined)'
PowerCLI C:> Update-Entity -Entity $Datacenter -Baseline
    $Baseline -Confirm:$false -GuestCreateSnapshot:$true

The preceding commands do not return any output.

Upgrading virtual machine hardware

To upgrade virtual machine hardware, you have to use the VM Hardware Upgrade to Match Host (Predefined) baseline. Before you can upgrade the hardware version of a virtual machine, the VMware Tools installed on the virtual machine, must be the latest version.

In the following example, we will upgrade the version of the virtual hardware on all virtual machines in the data center New York that have the latest version of the VMware Tools installed. During the upgrade, the virtual machine will be shutdown, upgraded to the hardware version that matches the vSphere version of the host, and finally the virtual machine will be powered on.

PowerCLI C:> $Datacenter = Get-Datacenter -Name 'New York'
PowerCLI C:> $Baseline = Get-Baseline -Name 'VM Hardware
    Upgrade to Match Host (Predefined)'
PowerCLI C:> Update-Entity -Entity $Datacenter -Baseline
    $Baseline -Confirm:$false

The preceding commands do not return any output.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.100.34