0 Replies Latest reply on Apr 8, 2011 4:06 PM by KMSigma

    PowerShell Script to "auto-update" the MIB.cfg

    KMSigma

      Below is a PowerShell script that I've created to automatically download the latest MIB from the Solarwinds website.  I've run it a number of times and it seems to work without a problem.

      I've put some good comments in there, so that if you want, you can modify it for your installation (Windows Version, Orion Version, Solarwinds Product, etc.)

      I'd love feedback, so if you have any let me know.


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

      # Get-SolarwindsMIB.ps1

      #-------------------------------------------------------------------------------

      # Download and install the most recent MIB.cfg from Solarwinds

      # Script takes no parameters

      # Performs the following funcitons:

      #   Downloads the MIB.ZIP file

      #   Extracts the MIB.cfg from the MIB.ZIP

      #   Checks the creation date/time of the current MIB.cfg

      #   Compares that with the date/time of the downloaded MIB.cfg

      #   If the downloaded is newer, rename the older one with a date-stamp

      #      and replace with the downloaded copy.

      #   Stop all Solarwinds Services

      #   Stop all websites

      #   Start all Solarwinds Services

      #   Start all websites

      #-------------------------------------------------------------------------------

      # Tested with:

      #   Orion NPM 10.X.X

      #   Windows 20008 R2 x64

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

       

      # Location of the curernt MIB.cfg

      $OrionNPMMIBLocation = "C:\ProgramData\SolarWinds\MIBs.cfg"

       

      # MIB.zip download location

      $MIBLink = `

       "http://solarwinds.s3.amazonaws.com/solarwinds/Release/MIB-Database/MIBs.zip"

       

      # Temporary Location for working with the MIB

      $MIBZip  = "$env:temp\MIBS.zip"

       

      # Create a the name for the MIB.cfg file

      $MIBCfg  = $MIBZip.Replace("zip", "cfg")

       

      # Cleanup Temp Folder

      Remove-Item "$env:temp\*" -Force -ErrorAction SilentlyContinue

       

      # Create new Web Client

      $WebClient = New-Object System.Net.WebClient

       

      # Download from $MIBLink to $MIBZip

      $WebClient.DownloadFile($MIBLink, $MIBZip)

       

      # Create Shell Object

      $Shell = New-Object -com Shell.Application

      $Location = $Shell.Namespace( $env:temp )

       

      # Extract Zip Contents

      $ZipFolder = $Shell.Namespace( $MIBZip )

      $Location.CopyHere( $ZipFolder.items() )

       

      # Compare UTC Creation date on the newly downloaded and the original MIB.cfg

      $DateNewFile = (Get-Item $MIBCfg             ).CreationTimeUtc

      $DateOldFile = (Get-Item $OrionNPMMIBLocation).CreationTimeUtc

       

      # If the newly downloaded one was created after the current one...

      if ( $DateNewFile -gt $DateOldFile )

      {

       

          Write-Host Replace MIB Configuration File

         

          # Rename current MIB.cfg to MIB-YYYYMMDD.cfg for fail-back if necessary

          Move-Item -Path $OrionNPMMIBLocation -Destination `

                  ( $OrionNPMMIBLocation.Split(".")[0] + "-" + `

                  (Get-Date -format "yyyyMMdd") + "." + `

                  $OrionNPMMIBLocation.Split(".")[1] )

         

          # Move the newly downloaded MIB.cfg to the proper location

          Move-Item -Path $MIBCfg -Destination `

                  ( (Get-Item ( $OrionNPMMIBLocation.Split(".")[0] + "-" + `

                  (Get-Date -format "yyyyMMdd") + "." + `

                  $OrionNPMMIBLocation.Split(".")[1] ) ).Directory.FullName )

       

          # Stop all Solarwinds Services

          Get-Service | `

            Where-Object { $_.DisplayName -match 'Solarwinds*' } | `

            Stop-Service

       

          # Stop all Websites

          Import-Module WebAdministration

          Get-WebSite | Stop-Website

         

          # Start all Solarwinds Services

          Get-Service | `

            Where-Object { $_.DisplayName -match 'Solarwinds*' } | `

            Start-Service

         

          # Start all Websites

          Get-WebSite | Start-WebSite

         

      }