Public/Catalog/Save-MyDellDriverCab.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function Save-MyDellDriverCab {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$DownloadPath,
        [string]$Expand
    )
    #=======================================================================
    # Require Dell Computer
    #=======================================================================
    if ((Get-MyComputerManufacturer -Brief) -ne 'Dell') {
        Write-Warning "Dell computer is required for this function"
        Break
    }
    #=======================================================================
    # Get-MyDellDriverCab
    #=======================================================================
    $GetMyDellDriverCab = Get-MyDellDriverCab | Select-Object LastUpdate,DriverName,Make,Generation,Model,SystemSku,DriverVersion,DriverReleaseId,OSVersion,OSArch,DownloadFile,SizeMB,DriverUrl,DriverInfo,Hash

    if ($GetMyDellDriverCab) {
        $GetMyDellDriverCab

        $DriverName = $GetMyDellDriverCab.DriverName
        $DownloadFile = $GetMyDellDriverCab.DownloadFile
        $SizeMB = $GetMyDellDriverCab.SizeMB
        $DriverUrl = $GetMyDellDriverCab.DriverUrl
        $Hash = $GetMyDellDriverCab.Hash

        $Source = $DriverUrl
        $Destination = 'C:\Drivers'
        $OutFile = Join-Path $Destination $DownloadFile

        if (-NOT (Test-Path "$Destination")) {
            New-Item $Destination -ItemType Directory -Force -ErrorAction Stop | Out-Null
        }

        Write-Host "Source: $Source" -ForegroundColor Cyan
        Write-Host "Destination: $Destination" -ForegroundColor Cyan
        Write-Host "OutFile: $OutFile" -ForegroundColor Cyan
        Write-Host "Be patient ... this is a $SizeMB MB file" -ForegroundColor Cyan
        #=======================================================================
        # Download Driver CAB
        #=======================================================================
        if (Get-Command 'curl.exe') {
            if (-NOT (Test-Path $OutFile)) {
                Write-Host "Downloading using cURL" -ForegroundColor Cyan
                & curl.exe --location --output "$OutFile" --progress-bar --url $Source
            }
        } else {
            Write-Warning "If you had cURL, this download would be much faster ..."
        }
        if (-NOT (Test-Path $OutFile)) {
            Write-Host "Downloading using BITS" -ForegroundColor Cyan
            Save-OSDDownload -BitsTransfer -SourceUrl $Source -DownloadFolder $Destination -ErrorAction SilentlyContinue | Out-Null
        }
        if (-NOT (Test-Path $OutFile)) {
            Write-Host "Downloading using WebClient" -ForegroundColor Cyan
            Save-OSDDownload -SourceUrl $Source -DownloadFolder $Destination -ErrorAction SilentlyContinue | Out-Null
        }
        
        if (Test-Path $OutFile) {
            $MyDellDriverFile = Get-Item $OutFile
            $ExpandPath = Join-Path $Destination $DriverName

            if (-NOT (Test-Path "$ExpandPath")) {
                New-Item $ExpandPath -ItemType Directory -Force -ErrorAction Stop | Out-Null
            }
    
            Write-Host "Expanding $DownloadFile to $ExpandPath" -ForegroundColor Cyan
            Expand -R "$($MyDellDriverFile.FullName)" -F:* "$ExpandPath" | Out-Null
            Return (Get-Item $ExpandPath).FullName
        } else {
            Write-Warning "Unable to download the Driver Cab"
            Return $null
        }

    }
}