Advertisement
Journeym

Untitled

Jul 28th, 2020
1,685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Array of advanced settings to apply
  2. $dataset = @(
  3.     [PSCustomObject]@{
  4.         Name  = "time.synchronize.continue"
  5.         Value = "FALSE"
  6.     },
  7.     [PSCustomObject]@{
  8.         Name  = "time.synchronize.restore"
  9.         Value = "FALSE"
  10.     },
  11.     [PSCustomObject]@{
  12.         Name  = "time.synchronize.resume.disk"
  13.         Value = "FALSE"
  14.     },
  15.     [PSCustomObject]@{
  16.         Name  = "time.synchronize.shrink"
  17.         Value = "FALSE"
  18.     },
  19.     [PSCustomObject]@{
  20.         Name  = "time.synchronize.tools.startup"
  21.         Value = "FALSE"
  22.     },
  23.     [PSCustomObject]@{
  24.         Name  = "time.synchronize.resume.host"
  25.         Value = "FALSE"
  26.     },
  27.     [PSCustomObject]@{
  28.         Name  = "devices.hotplug"
  29.         Value = "FALSE"
  30.     }
  31. )
  32. filter timestamp {"$(Get-Date -Format G): $_"}
  33. Connect-VIServer vcenter.contoso.com
  34. # Change to filter VM's
  35. $vms = Get-VM vmname.contoso.com
  36. foreach ($vm in $vms) {
  37.     Write-Output "Processing VM : $($vm)" | timestamp
  38.     foreach ($data in $dataset) {
  39.         $adv = Get-AdvancedSetting -Entity $vm
  40.         $index = $adv.Name.IndexOf($data.Name)
  41.         if ($index -ne -1) {
  42.             if ($data.Value -ne $adv[$index].Value) {
  43.                 Write-Output "$($adv[$index]) is not equal to $($data.Name):$($data.Value), enforcing Set-AdvancedConfig" | timestamp
  44.                 Get-AdvancedSetting -Entity $vms -Name $data.Name | Set-AdvancedSetting -Value $data.Value -Confirm:$false
  45.             }
  46.             else {Write-Output "$($adv[$index]) equals $($data.Name):$($data.Value), nothing to do..." | timestamp}
  47.         }
  48.         else {
  49.             Write-Output "$($data.Name):$($data.Value) entry does not exist, invoking New-AdvancedConfig..." | timestamp
  50.             $vm | New-AdvancedSetting -Name $data.Name -Value $data.Value -Confirm:$false
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement