PoshCode Archive  Artifact [a6514337b3]

Artifact a6514337b340a1e23b3fa7a3d9d8c7ecdcd74e1304fdecefe102739c7c7792ea:

  • File Check-latest-BIOS-Rev.ps1 — part of check-in [ff534b88b7] at 2018-06-10 13:14:14 on branch trunk — This script is pretty simple, it connects to a remote computer and grabs the BIOS class. It then connects to the Dell support page for the remote computer’s ServiceTag. If the computer is a Dell, it grabs the BIOS revision listed on the page. The inspiration came from reading the Scripting Guy blog about comments. (http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/16/add-excellent-comments-to-your-powershell-script.aspx) (user: Jeff Patton size: 3090)

# encoding: ascii
# api: powershell
# title: Check latest BIOS Rev
# description: This script is pretty simple, it connects to a remote computer and grabs the BIOS class. It then connects to the Dell support page for the remote computer’s ServiceTag. If the computer is a Dell, it grabs the BIOS revision listed on the page. The inspiration came from reading the Scripting Guy blog about comments. (http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/16/add-excellent-comments-to-your-powershell-script.aspx)
# version: 0.1
# type: class
# author: Jeff Patton
# license: CC0
# x-poshcode-id: 2679
# x-archived: 2016-03-16T14:11:32
# x-published: 2012-05-17T09:08:00
#
# Moved the download inside the check for Dell hardware.
#
$BiosRev = Get-WmiObject -Class Win32_BIOS -ComputerName $ComputerName -Credential $Credentials

# Shortened URL for the Dell Support page, fileid=441102, appears to be the identifier for BIOS downloads
# I tested this on a few different models of Dell workstations.

$DellBIOSPage = "http://support.dell.com/support/downloads/download.aspx?c=us&cs=RC956904&l=en&s=hied&releaseid=R294848&SystemID=PLX_960&servicetag=$($BiosRev.SerialNumber)&fileid=441102"

# This HTML code immediately preceed's the actual service tag, you can see it when you 'view source' on the page

$DellPageVersionString = "<span id=`"Version`" class=`"para`">"

If ($BiosRev.Manufacturer -match "Dell")
{
    $DellPage = (New-Object -TypeName net.webclient).DownloadString($DellBIOSPage)
    
    # Assuming that Dell BIOS rev's remain 3 characters, I find where my string starts and add the length to it
    # and the substring returns the BIOS rev.
    
    $DellCurrentBios = $DellPage.Substring($DellPage.IndexOf($DellPageVersionString)+$DellPageVersionString.Length,3)

    If (($BiosRev.SMBIOSBIOSVersion -eq $DellCurrentBios) -eq $false)
    {
        # Download the latest installer if the Rev's don't match
        
        # Assuming Dell continues to use FTP for downloads, find the download URL
        # This returns just the URL portion of the HTML code
        
        $BIOSDownloadURL = $DellPage.Substring($DellPage.IndexOf("http://ftp"),(($DellPage.Substring($DellPage.IndexOf("'http://ftp"),100)).indexof(".EXE"))+3)
        
        # Pull the filename from the end of the path, the 12's indicate 8+3 that Dell is using
        # for filenames, if that changes this should as well.
        
        $BIOSFile = $BIOSDownloadURL.Substring(($BIOSDownloadURL.Length)-12,12)

        If ((Test-Path "C:\Dell\") -eq $false)
        {
            New-Item -Path "C:\" -Name "Dell" -ItemType Directory
        }
        If ((Test-Path "C:\Dell\$($ComputerName)") -eq $false)
        {
            New-Item -Path "C:\Dell" -Name $ComputerName -ItemType Directory
        }

        (New-Object -TypeName net.webclient).DownloadFile($BIOSDownloadURL,"C:\Dell\$($ComputerName)\$($BIOSFile)")

        Write-Host "Latest BIOS for $($ComputerName) downloaded to C:\Dell\$($ComputerName)\$($BIOSFile)"
    }
}