Hello,
I am trying to update multiple VMs that have been affected by a previous VMware bug that caused the disk.enableUUID value to be missing from a bunch of VMs.
Here is the bug in case anyone wants to reference it:
I needed a way to run this against multiple machines at the same time. I was able to piece together this script from a few different scripts I have used in the past.
# Load PowerCLI Plugin and connect to VCenter Server
Import-Module VMware.VimAutomation.Core -ErrorAction SilentlyContinue
connect-viserver VCENTERSERVERNAME
# Clear Report.csv Values From Previous Run
Clear-Content -Path .\report.csv
# CSV file with a column named vmName
Import-Csv -Path .\vmnames.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
$vm = Get-VM -Name $row.vmName
# Set disk.EnableUUID to True on all VMs listed in vmnames.csv
$vm | New-AdvancedSetting -name disk.EnableUUID -Value 'TRUE' -Force -Confirm:$false | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture -Append}
When I ran this without the -Append value at the end of the Export-Csv I only got the last VM the script ran against. After, I put append it would export all the results. However, I noticed that since I was appending if I didn't manually clear the file it would keep the previous results as well. So, I added the Clear-Content line to clear the file before it runs.
Also, I was getting prompted to confirm the value change for each individual VM so I added the -Confirm:$false value as well.
Is there a cleaner way of accomplishing what I want or do you think this is good as is?
My last question is can I change the disk.enableUUID value while the VM is running or do I need to power them off first? I know it won't take effect until the VM is powered down and on but I wasn't sure if it would cause any major issues to a running VM. I see can't change it from the Configuration Parameters in the Edit Settings within the GUI when it's running so I was concerned.
I'm afraid that is because you are doing the Export-Csv inside the Foreach-Objct block, meaning you overwrite the CSV at each loop.
You can move the Export-Csv outside the loop.
# Load PowerCLI Plugin and connect to VCenter Server
Import-Module VMware.VimAutomation.Core -ErrorAction SilentlyContinue
connect-viserver VCENTERSERVERNAME
# Clear Report.csv Values From Previous Run
Clear-Content -Path .\report.csv
# CSV file with a column named vmName
Import-Csv -Path .\vmnames.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
$vm = Get-VM -Name $row.vmName
# Set disk.EnableUUID to True on all VMs listed in vmnames.csv
$vm | New-AdvancedSetting -name disk.EnableUUID -Value 'TRUE' -Force -Confirm:$false
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm afraid that is because you are doing the Export-Csv inside the Foreach-Objct block, meaning you overwrite the CSV at each loop.
You can move the Export-Csv outside the loop.
# Load PowerCLI Plugin and connect to VCenter Server
Import-Module VMware.VimAutomation.Core -ErrorAction SilentlyContinue
connect-viserver VCENTERSERVERNAME
# Clear Report.csv Values From Previous Run
Clear-Content -Path .\report.csv
# CSV file with a column named vmName
Import-Csv -Path .\vmnames.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
$vm = Get-VM -Name $row.vmName
# Set disk.EnableUUID to True on all VMs listed in vmnames.csv
$vm | New-AdvancedSetting -name disk.EnableUUID -Value 'TRUE' -Force -Confirm:$false
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That worked great, thanks! Do you know if I execute the script to add the disk.enableuuid value while the VM is running if it will break anything? As I said before I know it won't take affect until the VMs are power cycled but I'm trying to update this value on multiple VMs. I'm just concerned about something crashing.
The KB you referenced earlier does say to power off the VM.
So I think it would be advisable to follow that advice
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Fair enough. Thanks again for your help. I did reach out to support and this was their response for anyone that is curious:
I understand from the case notes that you have queries in regards to the script for DIsk UUID
If the script is run on a powered on VM, it would not apply the change as the Host would be holding a lock on the vmx file.
As mentioned by you, this would apply only after a power cycle on the VM and even if script is ran on powered on VMs, it should cause no issues.
I have not tested this script on a Production setup, I would recommend first trying on a couple of VMs and then applying to rest of them, just to be sure.