Digressive / gal-site-utterances

0 stars 0 forks source link

utils/hyperv-backup-utility/ #11

Open utterances-bot opened 11 months ago

utterances-bot commented 11 months ago

Hyper-V Backup Utility – Mike Galvin - Technical Consultant

20+ years as a SysAdmin. In-depth guides about Windows, PowerShell and Network Administration.

https://gal.vin/utils/hyperv-backup-utility/

mannyagre commented 11 months ago

You are using strings for VMStates, that will only work if the host is in english.

You can use their numeric value instead so it will be compatible with any language:

Numeric values for VmState:

Unknown 0 (Default) The state of the VM could not be determined.

Enabled 2 The VM is running.

Disabled 3 The VM is turned off.

Paused 32768 The VM is paused.

Suspended 32769 The VM is in a saved state.

Starting 32770 The VM is starting.

Saving 32773 The VM is saving its state.

Stopping 32774 The VM is turning off.

Pausing 32776 The VM is pausing.

Resuming 32777 The VM is resuming from a paused state.

For example, you can use

If ($VmState.State -ne 3 -OR $VmState.State -ne 32769 -AND $VmState.Status -ne 2)

instead of

If ($VmState.State -ne 'Off' -OR $VmState.State -ne 'Saved' -AND $VmState.Status -ne 'Operating normally')

mannyagre commented 11 months ago

I just found out that some of the numeric values in the microsoft doc are wrong, I extracted the numeric values for states from wmi and tested it in get-vm.

The correct ones are: saved 6 running 2 paused 9 off 3

But I couldn't find the numeric values for status so I ended up using another condition adding support for spanish, for example:

If ($VmState.State -ne 3 -OR $VmState.State -ne 6 -AND ($VmState.Status -ne 'Operating normally' -OR $VMState.Status -ne 'Funcionamiento normal'))

In every piece of code that uses state I changed for the numeric value, but for the status value I had to add the spanish version, if you find the numeric values for status please tell me.