Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Downloads the latest driver pack from Dell for any model or models you specify
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromPipeline=$true,
Position=0)]
[String[]]$Model,
[Parameter(Mandatory=$true,
Position=1)]
[ValidateSet("Windows 10","Windows 8.1","Windows 8","Windows 7")]
$OperatingSystem,
[Parameter(Mandatory=$true,
Position=2)]
[String]$DownloadDirectory
)
Begin
{
function Get-LatestDellDriverPackURL {
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[String]$Model,
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=1)]
[ValidateSet("Windows 10","Windows 8.1","Windows 8","Windows 7")]
$OperatingSystem
)
# Remove the "E" prefix character from Latitude models due to some dodgy Dell URLs...
If ($Model.ToCharArray()[0] -eq "E" -and $Model -notmatch "Embedded")
{
$Model = $Model.Replace("E","")
}
# Find the specific wiki page for the model from the main wiki page
$URI = "http://en.community.dell.com/techcenter/enterprise-client/w/wiki/2065.dell-command-deploy-driver-packs-for-enterprise-client-os-deployment"
Try
{
$HTML = Invoke-WebRequest -Uri $URI -ErrorAction Stop
If ($OperatingSystem -eq "Windows 8")
{
# Filter out Windows 8.1 from the results if it's just Windows 8
$Href = $HTML.AllElements | Where {$_.innerText -match ("$Model" + " W") -and $_.innerText -match $OperatingSystem -and $_.innerText -notmatch "8.1" -and $_.innerText -match "Driver" -and $_.tagName -eq "A"} | Select -ExpandProperty href
}
Else
{
$Href = $HTML.AllElements | Where {$_.innerText -match ("$Model" + " W") -and $_.innerText -match $OperatingSystem -and $_.innerText -match "Driver" -and $_.tagName -eq "A"} | Select -ExpandProperty href
}
}
Catch
{
$_
Return
}
If (!$Href)
{
Write-Error "No Wiki page found for $Model and $OperatingSystem."
Return
}
# Find the download URL from the model
$URI = "http://en.community.dell.com/$Href"
Try
{
$HTML = Invoke-WebRequest -Uri $URI -ErrorAction Stop
$CabDownloadLink = $HTML.AllElements | Where {$_.innerHTML -match "Download Now" -and $_.tagName -eq "A"} | Select -ExpandProperty href
Return $CabDownloadLink
}
Catch
{
$_
Return
}
Write-Error "No download URL found for $Model."
}
# Start a timer
$Stopwatch = New-Object System.Diagnostics.Stopwatch
$Stopwatch.Start()
}
Process
{
Foreach ($System in $Model)
{
Write-Verbose "Finding the download URL for '$System' and '$OperatingSystem'"
Try
{
# Get the download URL
$URL = Get-LatestDellDriverPackURL -Model $System -OperatingSystem $OperatingSystem -ErrorAction Stop
}
Catch
{
$Stopwatch.Stop()
$_
Return
}
Write-Verbose "Initiating download of URL '$URL' with BITS"
Try
{
# Begin the download
Start-BitsTransfer -Source $URL -Destination $DownloadDirectory
}
Catch
{
$Stopwatch.Stop()
$_
Return
}
}
}
End
{
$Stopwatch.Stop()
Write-Verbose "Completed in $($Stopwatch.Elapsed.Minutes) minutes and $($Stopwatch.Elapsed.Seconds) seconds"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.