VMware Cloud Community
Phoenix_LetsGo
Contributor
Contributor

Script to grab Operating system and assign to drs group

Hey Everyone,

I need a powershell script that grabs the Operating System and if Linux assigns to a DRS group.

 

The goal is to put new VMs into a DRS group that will locate VMs only on licensed ESXi hosts via DRS rules (DRS groups.)

 

Who has a script like that.  

0 Kudos
4 Replies
Phoenix_LetsGo
Contributor
Contributor

I found a good link that has commands I think will be in this group:    https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Powercli-Script-for-Getting-VMHost-Gro...

 

This might be helpful getting the OS:  

 

Get-VM | Select @{Label = "VM Name" ; Expression = {$_.Name} },@{Label = "Guest OS" ; Expression = {$_.ExtensionData.Config.GuestFullName} }| Export-CSV "vm_os_info.csv"

0 Kudos
LucD
Leadership
Leadership

Something like this?

$vms = Get-VM | where{$_.Guest.OSFullName -match 'Linux} 

Get-Cluster -Name MyCluster | Get-DrsClusterGroup -Name 'LinuxVM' |
Set-DrsClusterGroup -Add -VM $vms


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

Phoenix_LetsGo
Contributor
Contributor

Here is what I have so far, not sure if I am properly limiting the cluster:

 

Get-Cluster -Name TST

#This line identifies the predefined DRS vmgroup:
$vmGroup = Get-DrsClusterGroup -Name "TST_Matthew"

#This line identifies the VMs that are identified as Linux VMs from VMware tools:
$vmList = Get-VM | Where-Object {$_.Guest.OSFullName -like "*Linux*"}

#This line adds the vms to the specific DRS group:
Set-DrsClusterGroup -VM $vmList -DrsClusterGroup $vmGroup -Add

0 Kudos
LucD
Leadership
Leadership

Your code is not limiting the group to a specific cluster.
What is wrong with the code I provided earlier?


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

0 Kudos