Skip to content

Set-HostProfile

VMware: Modifies the specified host profile

#Requires -Version 5.1
#Requires -Modules VMware.VimAutomation.Core
[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$VIServer,
    [Parameter(Mandatory = $true)]
    [pscredential]$VICredential,
    [Parameter(Mandatory = $true)]
    [string]$ProfileName,
    [string]$Description,
    [string]$NewName
)
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 -Server $vmServer -Name $ProfileName -ErrorAction Stop
        if (-not [System.String]::IsNullOrWhiteSpace($Description)) {
            $null = Set-VMHostProfile -Profile $profile -Server $vmServer -Description $Description -Confirm:$false -ErrorAction Stop
        }
        if (-not [System.String]::IsNullOrWhiteSpace($NewName)) {
            $null = Set-VMHostProfile -Profile $profile -Server $vmServer -Name $NewName -Confirm:$false -ErrorAction Stop
        }
        $result = Get-VMHostProfile -Server $vmServer -Name $ProfileName -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

Name of the host profile to modify

New description for the host profile

New name for the host profile

An interactive directory of PowerShell scripts.