You could store the settings at the start in a hash table.
And then do something like this
Foreach ($vm in Get-VM)
{
$tab = @{}
$date=Get-Date -format "ddMMyy_HHmm"
Get-AdvancedSetting -Entity $vm | ForEach-Object -Process {
$tab.Add($_.Name,$_.Value)
}
New-AdvancedSetting -Entity $vm -Name vmci0.unrestricted -Value FALSE -Confirm:$False -Force:$True
# repeat for other settings
Get-AdvancedSetting -Entity $vm |
Select Name,@{N='OldValue';E={$tab[$_.Name]}},@{N='NewValue';E={$_.Value}} |
Export-Csv -Path "$($vm.Name)_Settings_$($date).csv" -NoTypeInformation -UseCulture
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference