PoshCode Archive  Artifact [4f7c91c53b]

Artifact 4f7c91c53bb41b7cba0cc7b7e6711e8bcff2ceda5ca2abe0a7768f4a5a196b6c:

  • File Create-a-VIAccount.ps1 — part of check-in [6b5760f6c3] at 2018-06-10 12:58:01 on branch trunk — Create a VIAccount object suitable for use with New-VIPermission, Get-VIPermission, etc. from PowerCLI. (user: unknown size: 936)

# encoding: ascii
# api: powershell
# title: Create a VIAccount
# description: Create a VIAccount object suitable for use with New-VIPermission, Get-VIPermission, etc. from PowerCLI.
# version: 0.1
# type: function
# license: CC0
# function: New-VIAccount
# x-poshcode-id: 1517
# x-archived: 2009-12-12T18:33:18
#
#
function New-VIAccount($principal) {
	$flags = `
		[System.Reflection.BindingFlags]::NonPublic    -bor
		[System.Reflection.BindingFlags]::Public       -bor
		[System.Reflection.BindingFlags]::DeclaredOnly -bor
		[System.Reflection.BindingFlags]::Instance
	$method = $defaultviserver.GetType().GetMethods($flags) |
		where { $_.Name -eq "VMware.VimAutomation.Types.VIObjectCore.get_Client" }
	$client = $method.Invoke($global:DefaultVIServer, $null)
	Write-Output `
		(New-Object VMware.VimAutomation.Client20.PermissionManagement.VCUserAccountImpl `
			-ArgumentList $principal, "", $client)
}