# 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 }
}