VMware Cloud Community
SCharchouf
Hot Shot
Hot Shot

Modifying Script for Advanced Settings

I found the below script and it's good, it Modify VM Advanced settings on an multiple VM, capture the VM Advanced setting details before and after VM setting changes for future comparison with the timestamp in .csv format.

I need assistance in order to modify the script and just to connect only via vCenter without preparing the ServerList file as the ENV is very huge and it's changing

Add-PSSnapin VMware.VimAutomation.Core

Connect-VIServer -Server vcenter.local -User username -Password Password

$ServerListFile = "ServerList.txt"

$ServerList = Get-Content $ServerListFile

Foreach ($vm in $ServerList)

{

    $date=get-Date -format "ddMMyy_HHmm"

    Get-VM $vm| Get-AdvancedSetting | Select Name, Value | Export-CSV $vm"_Before_$date.csv"

    New-AdvancedSetting -Entity $vm -Name vmci0.unrestricted -Value FALSE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name RemoteDisplay.maxConnections -Value '1' -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name tools.setInfo.sizeLimit -Value '1048576' -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name floppyX.present -Value FALSE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name serialX.present -Value FALSE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name parallelX.present -Value FALSE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name ideX:Y.present -Value FALSE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name isolation.device.connectable.disable -Value TRUE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name isolation.device.edit.disable -Value TRUE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name isolation.tools.unity.push.update.disable -Value TRUE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name isolation.tools.ghi.autologon.disable -Value TRUE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name isolation.bios.bbs.disable -Value TRUE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name vmsafe.enable -Value FALSE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name isolation.tools.copy.disable -Value TRUE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name isolation.tools.paste.disable -Value TRUE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name isolation.tools.autoInstall.disable -Value TRUE -Confirm:$False -Force:$True

    New-AdvancedSetting -Entity $vm -Name tools.guestlib.enableHostInfo -Value FALSE -Confirm:$False -Force:$True

    $date=get-Date -format "ddMMyy_HHmm"

    Get-VM $vm| Get-AdvancedSetting | Select Name, Value | Export-CSV $vm"_After_$date.csv"

    Start-VM -VM $vm

}

New-Item -ErrorAction Ignore -ItemType directory -Path Report

$path=$(get-location).Path+"\report\"

Move-Item *.csv $path -Force

9 Replies
LucD
Leadership
Leadership

If I understand your question correctly, you want to run the report for all VMs in a vCenter?

In that case, you could change the start of the script to the following.

PS1: I sincerely hope that you are not using such an old PowerCLI version that you need PSSnapin?

PS2: there is a Start-VM at the end of the script. Is that needed?

Connect-VIServer -Server vcenter.local -User username -Password Password

Foreach ($vm in Get-VM)

{

    $date=Get-Date -format "ddMMyy_HHmm"

    Get-AdvancedSetting -Entity $vm | Select Name, Value | Export-CSV $vm"_Before_$date.csv"


    New-AdvancedSetting -Entity $vm -Name vmci0.unrestricted -Value FALSE -Confirm:$False -Force:$True


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
SCharchouf
Hot Shot
Hot Shot

Thanks LucD as usualy you are the best Smiley Happy

PS:1 we have only this version of PowerCLI installed VMware vSphere PowerCLI 6.3 Release 1 build 3737840

PS2: Thanks for the information, I haven't seen it Smiley Happy

I will start the script as mentioned and keep you posted Smiley Happy

Reply
0 Kudos
SCharchouf
Hot Shot
Hot Shot

below the Script modified:

Connect-VIServer -Server vCenter.local

Foreach ($vm in Get-VM)

{

    $date=Get-Date -format "ddMMyy_HHmm"

    Get-AdvancedSetting -Entity$vm | Select Name, Value | Export-CSV $vm"_Before_$date.csv"

                  

                    New-AdvancedSetting -Entity $vm -Name isolation.tools.copy.disable -Value TRUE -Confirm:$False -Force:$True | select @{N='VM';E={$_.Entity.Name}},Name,Value

                    New-AdvancedSetting -Entity $vm -Name isolation.tools.paste.disable -Value TRUE -Confirm:$False -Force:$True | select @{N='VM';E={$_.Entity.Name}},Name,Value

}

New-Item -ErrorAction Ignore -ItemType directory -Path Report

$path=$(get-location).Path+"\Reports\"

Move-Item *.csv $path -Force

Issue:

  1. the folder Reports it's created once I run the report but without any files
  2. got this message when I run the script: 

Get-AdvancedSetting : A parameter cannot be found that matches parameter name 'Entity$vm'.

At .\AdvancedSettings_V1.ps1:9 char:25

+     Get-AdvancedSetting -Entity$vm | Select Name, Value | Export-CSV  ...

+                         ~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Get-AdvancedSetting], ParameterBindingException

    + FullyQualifiedErrorId : NamedParameterNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetAdvancedSetting

PS: it's possible to get the Report in the same CSV that show value before & after?

Reply
0 Kudos
LucD
Leadership
Leadership

Oops, a typo.
There was a space missing between Entity and $vm.
I corrected the code above.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

SCharchouf
Hot Shot
Hot Shot

Thanks LucD Smiley Happy

just one thing, it's possible to have the a single reports that contain the value before and the value after?

Reply
0 Kudos
LucD
Leadership
Leadership

You could store the settings at the start in a hash table.

And then do something like this

Connect-VIServer -Server vcenter.local -User username -Password Password

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

SCharchouf
Hot Shot
Hot Shot

Thanks LucD, but in that way, it will provide a report for each VM separately Smiley Happy

imagine 12000 VMs Smiley Happy

Reply
0 Kudos
LucD
Leadership
Leadership

Since the original script was also doing that, I assumed you wanted it that way.

But we can easily place everything in 1 CSV file.

Connect-VIServer -Server vcenter.local -User username -Password Password

$report = @()


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

  

    $report += Get-AdvancedSetting -Entity $vm |

    Select @{N='VM';E={$vm.Name}},Name,@{N='OldValue';E={$tab[$_.Name]}},@{N='NewValue';E={$_.Value}}

}


$report | Export-Csv -Path "Settings_$($date).csv" -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

SCharchouf
Hot Shot
Hot Shot

Perfect and many thanks Smiley Happy

Reply
0 Kudos