PoshCode Archive  Artifact [99d1e5523d]

Artifact 99d1e5523d8d1548068131720e7c1a6ae26270243449834f937bfbef9615f477:

  • File New-VMHostShellAccount.ps1 — part of check-in [4f6fd21bcc] at 2018-06-10 13:58:13 on branch trunk — The VI Toolkit comes with a cmdlet to create user accounts, but it does not allow for you to specify shell access. This script goes to the VI SDK to get the job done. (user: unknown size: 1123)

# encoding: ascii
# api: powershell
# title: New-VMHostShellAccount
# description: The VI Toolkit comes with a cmdlet to create user accounts, but it does not allow for you to specify shell access. This script goes to the VI SDK to get the job done.
# version: 0.1
# type: function
# license: CC0
# function: New-VMHostShellAccount
# x-poshcode-id: 563
# x-archived: 2008-09-15T21:33:44
#
#
# original by c_shanklin @ http://communities.vmware.com/message/1013362#1013362
function New-VMHostShellAccount {
	param (
		$Name,
		$Password = $null, 
		$Description = $null, 
		$PosixId = $null
	)
	$SvcInstance = Get-View serviceinstance
	$AcctMgr = Get-View $SvcInstance.Content.AccountManager
	$AcctSpec = new-object VMware.Vim.HostPosixAccountSpec
	$AcctSpec.id = $Name
	$AcctSpec.password = $Password
	$AcctSpec.description = $Description
	$AcctSpec.shellAccess = $true # Enable shell access
	$AcctSpec.posixId = $PosixId
	$AcctMgr.CreateUser($AcctSpec) # Create user
	# Write new user to output stream just as New-VMHostAccount would
	Get-VMHostAccount | Where-Object { $_.Id -eq $Name }
}