VMware Cloud Community
varonis
Enthusiast
Enthusiast

how to script this value to all my VM's,snapshot.maxSnapshots = X


i am trying to add a row to all my vms (1000 vms) :

snapshot.maxSnapshots = 4,


i cannot find any script ,Any help is welcome

10x.

0 Kudos
15 Replies
LucD
Leadership
Leadership

Try it like this

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec 
$spec
.extraConfig += New-Object VMware.Vim.OptionValue
$spec
.extraConfig[0].key = "snapshot.maxSnapshots"
$spec.extraConfig[0].value = 4
Get-VM
MyVM | %{$_.ExtensionData.ReconfigVM_Task($spec)}

You can of course update the selection criteria on the Get-VM cmdlet to find the guests you're after.


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

0 Kudos
varonis
Enthusiast
Enthusiast

thank u so much!!!, really helped me and did the job for me.

0 Kudos
admin
Immortal
Immortal

Hi, varonis,

LukeD gave you the correct script. The script is easily generated if you use project Onyx

a tool which enables you to create script while you click on the VSphere Client - like recording macros.

You can read this post -> LINK about which properties to change in order to generate the script you want.

Best regards,

Leni Kirilov

PowerCLI team

Zsoldier
Expert
Expert

Just an FYI, this KB states that you should only be using that parameter under VMWare Technical support guidance.

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=103128...

Out of curiosity, where would one find a reference to these settings?

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

For all VMX related parameters I start (of course) at the Sanbarrow site.

The snapshot.maxSnapshots can be found there as well.


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

0 Kudos
Zsoldier
Expert
Expert

Nice.  Thank Luc.

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

I know this is an old posting, but I have a quick question for Luc. Do you know if there is a way I can use this script and apply the changes to all host in a cluster?

Maybe using the Get-Cluster cmdlet?

0 Kudos
LucD
Leadership
Leadership

You mean to all VM on all ESXi host in a cluster ?


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

0 Kudos
ew0506
Contributor
Contributor

Yes.

0 Kudos
LucD
Leadership
Leadership

You could do something like this

$clusterName = "My Cluster"


$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec
.extraConfig += New-Object VMware.Vim.OptionValue
$spec
.extraConfig[0].key = "snapshot.maxSnapshots"
$spec.extraConfig[0].value = 4


Get-Cluster -Name $clusterName | Get-VM | %{

   $_.ExtensionData.ReconfigVM_Task($spec)}

}


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

0 Kudos
ew0506
Contributor
Contributor

Thanks for the quick feedback!!

0 Kudos
ew0506
Contributor
Contributor

Luc, I ran the command, but unfortunately I ran into my other dilemna. Since you can only connect to a host or VM in PowerCLI, when you issue the command against that cluster it tells you that I'm not connected to a host. Which in reality, even if I connect to a host that probably won't let me run the command against an entire cluster.

0 Kudos
LucD
Leadership
Leadership

Since you mentioned cluster, I assumed you were connecting to a vCenter.

Did you do a Connect-ViServer to the vCenter before running the script ?


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

0 Kudos
ew0506
Contributor
Contributor

Newbie mistake, now why didn't I think of that. I got it working now, thanks again!!!

0 Kudos
Wh33ly
Hot Shot
Hot Shot

It can be done easier while using

new-advancedsetting or set-advancedsetting, while using -force parameter the New-advancedsetting will override an existing one (so you don't have to use set-advancedsetting)

get-vm test123|new-AdvancedSetting -Name "snapshot.maxSnapshots" -Value "4" -Confirm:$false -Force

0 Kudos