Assign permission to a list of VMs using PowerCLI

Copy the list of VMs to a file C:\vmlist.txt.

$vmlist = Get-Content C:\vmlist.txt
foreach ($i in $vmlist)
{
Get-VM -Name $i | New-VIPermission -Role "ROLE_NAME" -Principal "Domain\GROUP"
OR
Get-VM -Name $i | New-VIPermission -Role "ROLE_NAME" -Principal "Domain\USER"
}

To verify

$vmlist = Get-Content C:\vmlist.txt
foreach ($i in $vmlist)
{
Get-VM -Name $i | Get-VIPermission | Where-Object {$_.Role -like "ROLE_NAME*"}
}
Advertisements

2 thoughts on “Assign permission to a list of VMs using PowerCLI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s