1 2 3 Previous Next 36 Replies Latest reply on Jul 19, 2018 3:58 PM by LucD

    Scripts Failing Suddenly

    pamiller21 Enthusiast

      I have had a number of scripts fail recently, I run the script manually and here is the script and output:

       

      #############################

      # Connect to vCenter        #

      #############################

      Start-Transcript -Path 'C:\Temp\script.log'

      Import-Module -Name VMware.PowerCLI

      Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -InvalidCertificateAction ignore -confirm:$false

      $vc = 'DNS'

      $Cred = Import-Clixml C:\util\Scripts\creds\autoitjob.xml

       

       

      Connect-VIServer $VC -Credential $Cred

       

       

      #############################

      #         Variables         #

      #############################

      $date=Get-Date -format "yyyy-MMM-d"

      $datetime=Get-Date

      $filelocation="C:\util\Scripts\Temp\Thin-$date.htm"

       

       

      #############################

      #          Content          #

      #############################

      $report = Get-VM | Get-HardDisk | where {$_.StorageFormat -ne "Thin"} | select Parent,StorageFormat,Filename

       

       

      #$report = Get-VM | Get-HardDisk |

      #where {$_.StorageFormat -ne "Thin"} |

      #select Parent,StorageFormat,Filename

       

      #############################

      # Add Text to the HTML file #

      #############################

      $report | ConvertTo-Html -title "VMware Thin Provision Check" -body "<H1>Vmware Thin Provision Check</H1>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File $filelocation

      ConvertTo-Html -title "VMware Thin Provision Check" -body "<H4>Date and time </H4>",$datetime -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation

      ConvertTo-Html -title "VMware Thin Provision Check" -body "<H4>VM Count</H4>",$report.Count -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation

       

       

      ######################

      # FTP HTML output #

      #####################

       

       

      #we specify the directory where all files that we want to upload 

      $Dir="$filelocation"

      #Below for test

      #$Dir="C:/Users/administrator/Desktop/tmp/"   

       

      #ftp server

      $ftp = "ftp://IP/internal-backups/datacenter/vcenter/misc-reports/Thin/"

      $user = "USER"

      $pass = "PW" 

       

      $webclient = New-Object System.Net.WebClient

       

      $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass) 

       

      #list every sql server trace file

      foreach($item in (dir $Dir "*.bak")){

          "Uploading $item..."

          $uri = New-Object System.Uri($ftp+$item.Name)

          $webclient.UploadFile($uri, $item.FullName)

      }

      ##############################

      # Disconnect session from VC #

      ##############################

      disconnect-viserver -confirm:$false

       

      OUTPUT:

      PS C:\util\scripts\Reports\Daily> .\ThinReport.ps1

      Transcript started, output file is C:\Temp\script.log

       

       

      Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout

                                                                                                        Seconds

      -----    -----------     ------------------- ------------------------  -------------------------- -------------------

      Session  UseSystemProxy  Multiple            Ignore                    False                      300

      User                     Multiple            Ignore                    False

      AllUsers

       

       

      IsConnected   : True

      Id            : /VIServer=vsphere.local\powercli@DNS:443/

      ServiceUri    : https://vcenter6.ruralnex.com/sdk

      SessionSecret : "7f2930a91d58a037dd232de769e26727c3338c71"

      Name          : vcenter6.ruralnex.com

      Port          : 443

      SessionId     : "7f2930a91d58a037dd232de769e26727c3338c71"

      User          : VSPHERE.LOCAL\PowerCLI

      Uid           : /VIServer=vsphere.local\powercli@vcenter6.ruralnex.com:443/

      Version       : 6.5.0

      Build         : 8667236

      ProductLine   : vpx

      InstanceUuid  : e66b929f-6e6e-4791-aafc-621177fc31b1

      RefCount      : 1

      ExtensionData : VMware.Vim.ServiceInstance

       

       

      Get-VM : 7/9/2018 11:01:54 AM   Get-VM          Value cannot be null.

      Parameter name: array

      At C:\util\scripts\Reports\Daily\ThinReport.ps1:22 char:11

      + $report = Get-VM | Get-HardDisk | where {$_.StorageFormat -ne "Thin"} ...

      +           ~~~~~~

          + CategoryInfo          : NotSpecified: (:) [Get-VM], VimException

          + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

       

       

      Uploading C:\util\Scripts\Temp\Thin-2018-Jul-9.htm...

        • 1. Re: Scripts Failing Suddenly
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          Which versions of PowerShell and PowerCLI are you using?

          Did you do a recent update of PowerCLI? Or PowerShell?

          Did you stop/start your PowerShell session from which you start the scripts?

          • 2. Re: Scripts Failing Suddenly
            pamiller21 Enthusiast

            PowerShell: 10.0.14393.0

            PowerCLI: 10.1.0.8403314

            I haven't updated anything, and only about half my scripts are failing.

            I have rebooted the script server entirely.  Issue still continued.

            Thank you for your help so far!

            • 3. Re: Scripts Failing Suddenly
              LucD Guru
              Community WarriorsvExpertUser Moderators

              That PowerShell version seems odd.

              Check what is in $PSVersionTable.

               

              Can you do this and check the versions fo the PowerCLI modules?

               

              Get-Module -Name VMware* -ListAvailable |

              Select Name,Version

              • 4. Re: Scripts Failing Suddenly
                pamiller21 Enthusiast

                Very sorry I ran a different command, but this is the version I get:

                 

                Name                           Value

                ----                           -----

                PSVersion                      5.1.14393.2273

                PSEdition                      Desktop

                PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}

                BuildVersion                   10.0.14393.2273

                CLRVersion                     4.0.30319.42000

                WSManStackVersion              3.0

                PSRemotingProtocolVersion      2.3

                SerializationVersion           1.1.0.1

                 

                VMware.DeployAutomation             6.7.0.8250345

                VMware.ImageBuilder                 6.7.0.8250345

                VMware.PowerCLI                     10.1.0.8403314

                VMware.Vim                          6.7.0.8343295

                VMware.VimAutomation.Cis.Core       10.1.0.8377811

                VMware.VimAutomation.Cloud          10.0.0.7893901

                VMware.VimAutomation.Common         10.1.0.8342134

                VMware.VimAutomation.Core           10.1.0.8344055

                VMware.VimAutomation.HA             6.5.4.7567193

                VMware.VimAutomation.HorizonView    7.1.0.7547311

                VMware.VimAutomation.License        10.0.0.7893904

                VMware.VimAutomation.Nsxt           10.1.0.8346947

                VMware.VimAutomation.PCloud         10.0.0.7893924

                VMware.VimAutomation.Sdk            10.1.0.8342078

                VMware.VimAutomation.Srm            10.0.0.7893900

                VMware.VimAutomation.Storage        10.1.0.8313015

                VMware.VimAutomation.StorageUtility 1.2.0.0

                VMware.VimAutomation.Vds            10.1.0.8344219

                VMware.VimAutomation.Vmc            10.0.0.7893902

                VMware.VimAutomation.vROps          10.0.0.7893921

                VMware.VumAutomation                6.5.1.7862888

                VMware.DeployAutomation             6.7.0.8250345

                VMware.ImageBuilder                 6.7.0.8250345

                VMware.PowerCLI                     10.1.0.8403314

                VMware.Vim                          6.7.0.8343295

                VMware.VimAutomation.Cis.Core       10.1.0.8377811

                VMware.VimAutomation.Cloud          10.0.0.7893901

                VMware.VimAutomation.Common         10.1.0.8342134

                VMware.VimAutomation.Core           10.1.0.8344055

                VMware.VimAutomation.HA             6.5.4.7567193

                VMware.VimAutomation.HorizonView    7.1.0.7547311

                VMware.VimAutomation.License        10.0.0.7893904

                VMware.VimAutomation.Nsxt           10.1.0.8346947

                VMware.VimAutomation.PCloud         10.0.0.7893924

                VMware.VimAutomation.Sdk            10.1.0.8342078

                VMware.VimAutomation.Srm            10.0.0.7893900

                VMware.VimAutomation.Storage        10.1.0.8313015

                VMware.VimAutomation.StorageUtility 1.2.0.0

                VMware.VimAutomation.Vds            10.1.0.8344219

                VMware.VimAutomation.Vmc            10.0.0.7893902

                VMware.VimAutomation.vROps          10.0.0.7893921

                VMware.VumAutomation                6.5.1.7862888

                • 5. Re: Scripts Failing Suddenly
                  LucD Guru
                  Community WarriorsUser ModeratorsvExpert

                  Looks like you have PowerCLI installed in 2 locations.

                  Possible in the C:\Program Files\WindowsPowerShell\Modules and C:\Users\<your-account>\Documents\WindowsPowerShell\Modules

                  Can you do

                  Get-Module -Name VMware* -ListAvailable
                  • 6. Re: Scripts Failing Suddenly
                    pamiller21 Enthusiast

                    You are correct, 2 locations.  How can I correct this?

                    • 7. Re: Scripts Failing Suddenly
                      LucD Guru
                      User ModeratorsCommunity WarriorsvExpert

                      In the output from Get-Module -Name VMware* -ListAvailable, you'll see the directories into which the modules are installed.

                      You can just delete the module folders in one of those directories.

                      • 8. Re: Scripts Failing Suddenly
                        pamiller21 Enthusiast

                        I deleted the directory and no change :/

                        • 9. Re: Scripts Failing Suddenly
                          LucD Guru
                          vExpertUser ModeratorsCommunity Warriors

                          Next step, delete all the PowerCLI directories and do the Install-Module again.

                          I suspect your installation might have an issue.

                          • 10. Re: Scripts Failing Suddenly
                            pamiller21 Enthusiast

                            Did that, same result. :/

                            • 11. Re: Scripts Failing Suddenly
                              LucD Guru
                              vExpertUser ModeratorsCommunity Warriors

                              Very strange.
                              Do you by any chance have another station where you can have PowerCLI installed?

                              Does that show the same behaviour?

                              • 12. Re: Scripts Failing Suddenly
                                pamiller21 Enthusiast

                                Ran it from my local machine and got the same error.

                                • 13. Re: Scripts Failing Suddenly
                                  LucD Guru
                                  Community WarriorsUser ModeratorsvExpert

                                  Both machines have the same OS?

                                  Same patch level?

                                  • 14. Re: Scripts Failing Suddenly
                                    pamiller21 Enthusiast

                                    Nope, one is a win16 server other is my laptop with windows 10

                                    1 2 3 Previous Next