adamjg
Hot Shot
Hot Shot

Setting SDRS VM Overrides per VM?

Jump to solution

I have a scripted process to create a new VM.  The script goes through and asks questions about VM type, IP, location, datastore clusters, etc. etc. and then creates the VM with a somewhat simple one liner:

#Creates the new VM

New-VM -Name $myVM -Template $myTemplate -OSCustomizationSpec $osCust -Datastore $myDatastoreCluster -ResourcePool $myCluster

All of the variables are determined based on the questions.  The only 2 issues I have are 1) the storage policy isn't set, and 2) it puts an entry into the VM overrides in the datastore cluster.  It puts the entries as the default, but since I do have some manually added SDRS VM overrides set, it's annoying to see one for every new build.

#1 I'm solving with PowerCLI 5.8.

#2 is where I'm struggling. I'm looking for either a way to have the VM created without the SDRS VM override entry, or to immediately delete this entry once it's set.

This thread:  changing vm storage drs automation level  details how to do this on a datastore cluster level, but is there a better way to do this on a specific VM level?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try like this

where {(Get-View $_.VM | Select -ExpandProperty Name) -match "^$($MyVM)$"} | %{


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

View solution in original post

0 Kudos
10 Replies
LucD
Leadership
Leadership

Afaik, it is the same method you need to use.

But in this case, you would just need to select the specific VM entry to change.

where {(Get-View $_.VM | Select -ExpandProperty Name) -match "^MyVM$"} | %{

Where MyVM would be the name of the Vm for who you want to change the settings.

Note that the -match operator works on a RegEx expression, hence the ^ and $ in the string to have an exact match of the name.


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

0 Kudos
adamjg
Hot Shot
Hot Shot

LucD wrote:

Afaik, it is the same method you need to use.

But in this case, you would just need to select the specific VM entry to change.

where {(Get-View $_.VM | Select -ExpandProperty Name) -match "^MyVM$"} | %{

Where MyVM would be the name of the Vm for who you want to change the settings.

Note that the -match operator works on a RegEx expression, hence the ^ and $ in the string to have an exact match of the name.

Oh cool, thanks for the quick reply. I suck at RegEx...what would the syntax be if I have a variable $myVM which is a string that contains the VM name?

0 Kudos
LucD
Leadership
Leadership

Try like this

where {(Get-View $_.VM | Select -ExpandProperty Name) -match "^$($MyVM)$"} | %{


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

0 Kudos
adamjg
Hot Shot
Hot Shot

I got it, using a few other posts in that thread.  Here's what I have, in case anyone else is looking at this:

$storMgr = Get-View StorageResourceManager

$spec = New-Object VMware.Vim.StorageDrsConfigSpec

$dsc = Get-Datastorecluster $datastorecluster

get-vm -Datastore $dsc | where {$_.Name -eq $MyVM} | %{

    $vmEntry = New-Object VMware.Vim.StorageDrsVmConfigSpec           

    $vmEntry.Operation = "add"           

    $vmEntry.Info = New-Object VMware.Vim.StorageDrsVmConfigInfo           

    $vmEntry.Info.Vm = $_.ExtensionData.MoRef           

    $spec.vmConfigSpec += $vmEntry            

}             

$storMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)

0 Kudos
LucD
Leadership
Leadership

Great, thanks for sharing


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

0 Kudos
iAndroid
Contributor
Contributor

We've got the very same issue: every time a new VM is being created with New-VM, an unwanted VM override entry is being created at the respective datastore cluster, and as there seems to be no way to keep the New-VM cmdlet from behaving like that, the only suitable options seems to be to delete the override entry right away after the VM has been created.

Now I'm not sure what the code provided by adamjg​ really does. I get it that the StorageDRS configuration of a given VM ($MyVM) is being extracted from the settings of a given storage cluster ($datastorecluster), but where exactly is this VM config being modified or (what we are looking for) being entirely deleted?

Or, to put it the other way round: what would be the correct code to entirely delete the override entry for the given VM $MyVM?

Thanks very much - this issue is annoying us since months an I'd be very grateful to get a solution.

0 Kudos
LucD
Leadership
Leadership

That code in fact creates (add) an empty override entry for each VM sitting on the datastorecluster.

I assume you want to remove each VM override?


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

0 Kudos
iAndroid
Contributor
Contributor

Luc, thanks for answering. No, we do not want to remove the overrides for any VM sitting on the datastore cluster, but only for the VM (known by name) which has just been created. The reason is that there are in fact some VMs for which we indeed want to have (and keep) an override, so deleting ​all​ overrides is not an option.

0 Kudos
LucD
Leadership
Leadership

Ok, the following removes one specific VM from the list.

$dscName = 'MyDSC'

$vmName = 'MyVM'

$storMgr = Get-View StorageResourceManager 

$spec = New-Object VMware.Vim.StorageDrsConfigSpec  

$dsc = Get-Datastorecluster $dscName 

$vm = Get-VM -Name $vmName

$vmEntry = New-Object VMware.Vim.StorageDrsVmConfigSpec             

$vmEntry.Operation = "remove"

$vmEntry.RemoveKey = $vm.ExtensionData.MoRef

$spec.vmConfigSpec += $vmEntry 

$storMgr.ConfigureStorageDrsForPod($dsc.ExtensionData.MoRef,$spec,$true)


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

0 Kudos
vThinkBeyondVM
VMware Employee
VMware Employee

Since this thread is about SDRS VM overrides, I thought to share my article on the same, which was written long back

Refer: Editing Storage DRS VM overrides : Java vSphere SDK and PowerCLI script - vThinkBeyondVM

This post will answer: What is SDRS VM overrides, how to configure and how to use PowerCLI or Java SDK to re-configure it.?

If it is useful, plz mark answer as correct or helpful.
----------------------------------------------------------------
Thanks & Regards
Vikas, VCP50, MCTS on AD, SCJP6.0.
http://vThinkBeyondVM.com
-----------------------------------------------------------------
Disclaimer: Any views or opinions expressed here are strictly my own. I am solely responsible for all content published here. Content published here is not read, reviewed or approved in advance by VMware and does not necessarily represent or reflect the views or opinions of VMware.

0 Kudos