Set-HostAccount
VMware: Configures a host account
#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]$Id,
[string]$Password,
[string]$Description,
[bool]$GrantShellAccess
)
Process {
$vmServer = $null
try {
$vmServer = Connect-VIServer -Server $VIServer -Credential $VICredential -ErrorAction Stop
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$uAccount = Get-VMHostAccount -Server $vmServer -Id $Id -ErrorAction Stop
$cmdArgs = @{ ErrorAction = 'Stop'; UserAccount = $uAccount; Confirm = $false }
if ($PSBoundParameters.ContainsKey('Password')) { $uAccount = Set-VMHostAccount @cmdArgs -Password $Password }
if ($PSBoundParameters.ContainsKey('Description')) { $uAccount = Set-VMHostAccount @cmdArgs -Description $Description }
if ($PSBoundParameters.ContainsKey('GrantShellAccess')) { $uAccount = Set-VMHostAccount @cmdArgs -GrantShellAccess $GrantShellAccess }
$result = $uAccount | 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
ID of the host user account to configure
New password for the host user account
Description of the specified account
Account is allowed to access the ESX shell