Public/Functions/split/Get-MyDellBios.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<#
.SYNOPSIS
This will return the latest compatible BIOS Update for your system as a PowerShell Object
 
.DESCRIPTION
This will return the latest compatible BIOS Update for your system as a PowerShell Object
Shortcut for Get-DellSystemCatalog -Component BIOS -Compatible
 
.LINK
https://osd.osdeploy.com/module/functions/dell/get-mydellbios
 
.NOTES
21.3.11 Pulling data from Local due to issues with the Dell site being down
21.3.5 Resolved issue with multiple objects
21.3.4 Initial Release
#>

function Get-MyDellBios {
    [CmdletBinding()]
    param ()

    $ErrorActionPreference = 'SilentlyContinue'
    #=================================================
    # Require Dell Computer
    #=================================================
    if ((Get-MyComputerManufacturer -Brief) -ne 'Dell') {
        Write-Warning "Dell computer is required for this function"
        Return $null
    }
    #=================================================
    # Current System Information
    #=================================================
    $SystemSKU = $((Get-WmiObject -Class Win32_ComputerSystem).SystemSKUNumber).Trim()
    $BIOSVersion = $((Get-WmiObject -Class Win32_BIOS).SMBIOSBIOSVersion).Trim()
    #=================================================
    # Get-DellSystemCatalog
    #=================================================
    #$GetMyDellBios = Get-DellSystemCatalog -Component BIOS -Compatible | Sort-Object ReleaseDate -Descending | Select-Object -First 1
    $GetMyDellBIOS = Get-DellBiosCatalog | Sort-Object ReleaseDate -Descending
    $GetMyDellBIOS | Add-Member -MemberType NoteProperty -Name 'Flash64W' -Value 'https://github.com/OSDeploy/OSDCloud/raw/main/BIOS/Flash64W_Ver3.3.8.cab'
    #=================================================
    # Filter Compatible
    #=================================================
    Write-Verbose "Filtering XML for items compatible with SystemSKU $SystemSKU"
    $GetMyDellBIOS = $GetMyDellBIOS | `
        Where-Object {$_.SupportedSystemID -contains $SystemSKU}
    #=================================================
    # Pick and Sort
    #=================================================
    $GetMyDellBios = $GetMyDellBios | Sort-Object ReleaseDate -Descending | Select-Object -First 1
    #Write-Verbose "You are currently running Dell Bios version $BIOSVersion" -Verbose
    #=================================================
    # Return
    #=================================================
    Return $GetMyDellBios
}
function Save-MyDellBios {
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline = $true)]
        [Alias ('DownloadFolder','Path')]
        [string]$DownloadPath = $env:TEMP
    )
    #Make sure Computer is a Dell
    if ((Get-MyComputerManufacturer -Brief) -eq 'Dell') {
        
        #See if we can get the Dell BIOS
        $GetMyDellBios = Get-MyDellBios

        if ($GetMyDellBios) {

            #See if the BIOS has already been downloaded
            if (Test-Path "$DownloadPath\$($GetMyDellBios.FileName)") {
                Write-Verbose -Verbose "Bios Update File: $DownloadPath\$($GetMyDellBios.FileName)"
                Get-Item "$DownloadPath\$($GetMyDellBios.FileName)"
            }
            elseif (Test-MyDellBiosWebConnection) {
                #Download the BIOS Update
                #$SaveMyDellBios = Save-OSDDownload -SourceUrl $GetMyDellBios.Url -DownloadFolder "$DownloadPath"
                $SaveMyDellBios = Save-WebFile -SourceUrl $GetMyDellBios.Url -DestinationDirectory "$DownloadPath"
                Start-Sleep -Seconds 1

                #Make sure the BIOS Downloaded
                if (Test-Path "$($SaveMyDellBios.FullName)") {
                    Write-Verbose -Verbose "Bios Update Download: $($SaveMyDellBios.FullName)"
                    Get-Item "$($SaveMyDellBios.FullName)"
                }
                else {
                    Write-Warning "Could not download the Dell BIOS Update"
                }
            }
            else {
                Write-Warning "Could not verify an Internet connection for the Dell Bios"
            }
        }
        else {
            Write-Warning "Unable to determine a suitable Bios update for this Computer Model"
        }
    }
}
<#
.SYNOPSIS
Downloads and installed a compatible BIOS Update for your Dell system
 
.DESCRIPTION
Downloads and installed a compatible BIOS Update for your Dell system
BitLocker friendly, but you need Admin Rights
Logs to $env:TEMP\Update-MyDellBios.log
 
.EXAMPLE
Update-MyDellBios
Downloads and launches the Dell BIOS Update. Does not automatically install the BIOS Update
 
.EXAMPLE
Update-MyDellBios -Silent
Yes, this will update your BIOS silently, and NOT reboot when its done
 
.EXAMPLE
Update-MyDellBios -Silent -Reboot
Yes, this will update your BIOS silently, AND reboot when its done
 
.LINK
https://osd.osdeploy.com/module/functions/dell/update-mydellbios
 
.NOTES
21.3.9 Started adding logic for WinPE
21.3.5 Resolved issue with multiple objects
21.3.4 Initial Release
#>

function Update-MyDellBios {
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline = $true)]
        [Alias ('DownloadFolder','Path')]
        [string]$DownloadPath = $env:TEMP,
        [System.Management.Automation.SwitchParameter]$Force,
        [System.Management.Automation.SwitchParameter]$Reboot,
        [System.Management.Automation.SwitchParameter]$Silent
    )
    #=================================================
    # Block
    #=================================================
    Block-StandardUser
    #=================================================
    # Require Dell Computer
    #=================================================
    if ((Get-MyComputerManufacturer -Brief) -ne 'Dell') {
        Write-Warning "Dell computer is required for this function"
        Return $null
    }
    #=================================================
    # Current System Information
    #=================================================
    $SystemSKU = $((Get-WmiObject -Class Win32_ComputerSystem).SystemSKUNumber).Trim()
    $BIOSVersion = $((Get-WmiObject -Class Win32_BIOS).SMBIOSBIOSVersion).Trim()
    #=================================================
    # Compare
    #=================================================
    $GetMyDellBios = Get-MyDellBios | Sort-Object ReleaseDate -Descending | Select-Object -First 1

    if ($GetMyDellBios.DellVersion -eq (Get-MyBiosVersion)) {
        Write-Warning "Update-MyDellBios: Current BIOS version $(Get-MyBiosVersion) is already the latest version"
        Start-Sleep -Seconds 5
    }
    if (($GetMyDellBios.DellVersion -lt (Get-MyBiosVersion)) -or ($Force.IsPresent) ) {
        #=================================================
        # Download
        #=================================================
        $SaveMyDellBios = Save-MyDellBios -DownloadPath $DownloadPath
        if (-NOT ($SaveMyDellBios)) {Return $null}
        if (-NOT (Test-Path $SaveMyDellBios.FullName)) {Return $null}
    
        if (($env:SystemDrive -eq 'X:') -and ($env:PROCESSOR_ARCHITECTURE -match '64')) {
            $SaveMyDellBiosFlash64W = Save-MyDellBiosFlash64W -DownloadPath $DownloadPath
            if (-NOT ($SaveMyDellBiosFlash64W)) {Return $null}
            if (-NOT (Test-Path $SaveMyDellBiosFlash64W.FullName)) {Return $null}
        }
        $SaveMyDellBiosFlash64W = Save-MyDellBiosFlash64W -DownloadPath $DownloadPath
        #=================================================
        # BitLocker
        #=================================================
        if ($env:SystemDrive -ne 'X:') {
            Write-Verbose "Checking for BitLocker" -Verbose
            #http://www.dptechjournal.net/2017/01/powershell-script-to-deploy-dell.html
            #https://github.com/dptechjournal/Dell-Firmware-Updates/blob/master/Install_Dell_Bios_upgrade.ps1
            $GetBitLockerVolume = Get-BitLockerVolume | Where-Object { $_.ProtectionStatus -eq "On" -and $_.VolumeType -eq "OperatingSystem" }
            if ($GetBitLockerVolume) {
                Write-Verbose "Suspending BitLocker for 1 Reboot"
                Suspend-BitLocker -Mountpoint $GetBitLockerVolume -RebootCount 1
                if (Get-BitLockerVolume -MountPoint $GetBitLockerVolume | Where-Object ProtectionStatus -eq "On") {
                    Write-Warning "Couldn't suspend Bitlocker"
                    Return $null
                }
            } else {
                Write-Verbose "BitLocker was not enabled" -Verbose
            }
        }
        #=================================================
        # Arguments
        #=================================================
        $BiosLog = Join-Path $env:TEMP 'Update-MyDellBios.log'
    
        $Arguments = "/l=`"$BiosLog`""
        if ($Reboot) {
            $Arguments = $Arguments + " /r /s"
        } elseif ($Silent) {
            $Arguments = $Arguments + " /s"
        }
        #=================================================
        # Execution
        #=================================================
        if (($env:SystemDrive -eq 'X:') -and ($env:PROCESSOR_ARCHITECTURE -match '64')) {
            $Arguments = "/b=`"$($SaveMyDellBios.FullName)`" " + $Arguments
            Write-Verbose "Start-Process -WorkingDirectory `"$($SaveMyDellBios.Directory)`" -FilePath `"$($SaveMyDellBiosFlash64W.FullName)`" -ArgumentList $Arguments -Wait" -Verbose
            Start-Process -WorkingDirectory "$($SaveMyDellBios.Directory)" -FilePath "$($SaveMyDellBiosFlash64W.FullName)" -ArgumentList $Arguments -Wait -ErrorAction Inquire
        }
        else {
            Write-Verbose "Start-Process -FilePath `"$($SaveMyDellBios.FullName)`" -ArgumentList $Arguments -Wait" -Verbose
            Start-Process -FilePath "$($SaveMyDellBios.FullName)" -ArgumentList $Arguments -Wait -ErrorAction Inquire
        }
        #=================================================
    }
}
function Save-MyDellBiosFlash64W {
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline = $true)]
        [Alias ('DownloadFolder','Path')]
        [string]$DownloadPath = $env:TEMP
    )

    if ((Get-MyComputerManufacturer -Brief) -eq 'Dell') {
        $GetMyDellBios = Get-MyDellBios
        if ($GetMyDellBios) {
            if (Test-WebConnection -Uri $GetMyDellBios.Flash64W) {
                #$SaveMyDellBiosFlash64W = Save-OSDDownload -SourceUrl $GetMyDellBios.Flash64W -DownloadFolder "$DownloadPath"
                $SaveMyDellBiosFlash64W = Save-WebFile -SourceUrl $GetMyDellBios.Flash64W -DestinationDirectory "$DownloadPath"
                Expand -R "$($SaveMyDellBiosFlash64W.FullName)" -F:* "$DownloadPath" | Out-Null
                if (Test-Path (Join-Path $DownloadPath 'Flash64W.exe')) {
                    Get-Item (Join-Path $DownloadPath 'Flash64W.exe')
                }
            }
            else {
                Write-Warning "Could not verify an Internet connection for the Dell Bios"
            }
        }
        else {
            Write-Warning "Unable to determine a suitable Bios update for this Computer Model"
        }
    }
}
function Test-MyDellBiosWebConnection {
    [CmdletBinding()]
    param ()
    
    $GetMyDellBios = Get-MyDellBios
    if ($GetMyDellBios) {
        Test-WebConnection -Uri $GetMyDellBios.Url
    } else {
        Return $false
    }
}