VMware Cloud Community
LPLAdmin
Enthusiast
Enthusiast
Jump to solution

Powercli to apply a role to just Linux VM's

Does anyone have a script to apply a role to just Linux VM's in your environment or Windows VM's?

 

Thanks,

 

Pete

0 Kudos
2 Solutions

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

With a Where-clause you can filter out the Linux VMs from a Get-VM.
Then it is just a matter of using the New-VIPermssion cmdlet on those VMs.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Zsoldier
Expert
Expert
Jump to solution

In case you need a little help:

$linuxvms = Get-VM | where{$_.ExtensionData.Config.GuestFullname -match "Red Hat Enterprise Linux"}
Foreach ($linuxvm in $linuxvms)
{
New-VIPermission -role "Role Name" -principal "AD Group Name" -Entity $linuxvm
}

 

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

With a Where-clause you can filter out the Linux VMs from a Get-VM.
Then it is just a matter of using the New-VIPermssion cmdlet on those VMs.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

LPLAdmin
Enthusiast
Enthusiast
Jump to solution

Luc,

 

This is what I have.  

$linuxvms = Get-VM | where{$_.ExtensionData.Config.GuestFullname -match "Red Hat Enterprise Linux"}
New-VIPermission -role "Role Name" -principal "AD Group Name" -Entity $linuxvms

Got this error.

New-VIPermission : Cannot process argument transformation on parameter 'Entity'. This parameter no longer accepts an array. As an alternative you may pass multiple values by pipeline (if supported by the
parameter).

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That indicates that more than 1 VM is returned (passed the Where-clause).
You can pipe the result to a Foreach loop, and handle the VMs one-by-one inside that loop.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Zsoldier
Expert
Expert
Jump to solution

In case you need a little help:

$linuxvms = Get-VM | where{$_.ExtensionData.Config.GuestFullname -match "Red Hat Enterprise Linux"}
Foreach ($linuxvm in $linuxvms)
{
New-VIPermission -role "Role Name" -principal "AD Group Name" -Entity $linuxvm
}

 

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos