9 Replies Latest reply on Sep 8, 2020 4:58 AM by SCharchouf

    Modifying Script for Advanced Settings

    SCharchouf Enthusiast

      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

        • 1. Re: Modifying Script for Advanced Settings
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Modifying Script for Advanced Settings
            SCharchouf Enthusiast

            Thanks LucD as usualy you are the best

             

            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

             

            I will start the script as mentioned and keep you posted

            • 3. Re: Modifying Script for Advanced Settings
              SCharchouf Enthusiast

              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?

              • 4. Re: Modifying Script for Advanced Settings
                LucD Guru
                vExpertUser ModeratorsCommunity Warriors

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

                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                • 5. Re: Modifying Script for Advanced Settings
                  SCharchouf Enthusiast

                  Thanks LucD

                   

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

                  • 6. Re: Modifying Script for Advanced Settings
                    LucD Guru
                    vExpertCommunity WarriorsUser Moderators

                    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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                    • 7. Re: Modifying Script for Advanced Settings
                      SCharchouf Enthusiast

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

                       

                      imagine 12000 VMs

                      • 8. Re: Modifying Script for Advanced Settings
                        LucD Guru
                        vExpertUser ModeratorsCommunity Warriors

                        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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                        1 person found this helpful
                        • 9. Re: Modifying Script for Advanced Settings
                          SCharchouf Enthusiast

                          Perfect and many thanks