Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Array of advanced settings to apply
- $dataset = @(
- [PSCustomObject]@{
- Name = "time.synchronize.continue"
- Value = "FALSE"
- },
- [PSCustomObject]@{
- Name = "time.synchronize.restore"
- Value = "FALSE"
- },
- [PSCustomObject]@{
- Name = "time.synchronize.resume.disk"
- Value = "FALSE"
- },
- [PSCustomObject]@{
- Name = "time.synchronize.shrink"
- Value = "FALSE"
- },
- [PSCustomObject]@{
- Name = "time.synchronize.tools.startup"
- Value = "FALSE"
- },
- [PSCustomObject]@{
- Name = "time.synchronize.resume.host"
- Value = "FALSE"
- },
- [PSCustomObject]@{
- Name = "devices.hotplug"
- Value = "FALSE"
- }
- )
- filter timestamp {"$(Get-Date -Format G): $_"}
- Connect-VIServer vcenter.contoso.com
- # Change to filter VM's
- $vms = Get-VM vmname.contoso.com
- foreach ($vm in $vms) {
- Write-Output "Processing VM : $($vm)" | timestamp
- foreach ($data in $dataset) {
- $adv = Get-AdvancedSetting -Entity $vm
- $index = $adv.Name.IndexOf($data.Name)
- if ($index -ne -1) {
- if ($data.Value -ne $adv[$index].Value) {
- Write-Output "$($adv[$index]) is not equal to $($data.Name):$($data.Value), enforcing Set-AdvancedConfig" | timestamp
- Get-AdvancedSetting -Entity $vms -Name $data.Name | Set-AdvancedSetting -Value $data.Value -Confirm:$false
- }
- else {Write-Output "$($adv[$index]) equals $($data.Name):$($data.Value), nothing to do..." | timestamp}
- }
- else {
- Write-Output "$($data.Name):$($data.Value) entry does not exist, invoking New-AdvancedConfig..." | timestamp
- $vm | New-AdvancedSetting -Name $data.Name -Value $data.Value -Confirm:$false
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement