Thanks, guys! I have tested the script on three laptops and it seems fine, BIOS is getting downloaded and installed.
However, I'm struggling with a stationary computer and I suspect these lines to be problematic.
$TargetLink = $Target.InstallableItem.OriginFile.OriginUri
$TargetFileName = $Target.InstallableItem.OriginFile.FileName
Invoke-WebRequest -Uri $TargetLink -OutFile "$scriptDirectory\Files\$ComputerModel\$TargetFileName" -UseBasicParsing -Verbose
The error message that keeps popups up would be "Cannot convert 'System.Object[]' to the type 'System.Uri' required by parameter 'Uri'. Specified method is not supported." It complains specifically over would be Invoke-WebRequest...
The whole code:
$ComputerModel = Get-WmiObject -Class Win32_computersystem | Select-Object -ExpandProperty Model
# Test if Path exsist, otherwise create it
$path = "$ScriptDirectory\Files\$Computermodel"
If(!(test-path -PathType container $path))
{
New-Item -ItemType Directory -Path $path
}
# <FORMAT CAB DOWNLOAD PATH>
$CabPath = "$ScriptDirectory\Files\$Computermodel\dellsdpcatalogpc.cab"
$destination = "$ScriptDirectory\Files\$Computermodel"
# Download Dell Cab File
Invoke-WebRequest -Uri "https://downloads.dell.com/Catalog/DellSDPCatalogPC.cab" -OutFile $CabPath -UseBasicParsing -Verbose
[int32]$n=1
While(!(Test-Path $CabPath) -and $n -lt '3'){
Invoke-WebRequest -Uri "https://downloads.dell.com/Catalog/DellSDPCatalogPC.cab" -OutFile $CabPath -UseBasicParsing -Verbose
$n++
}
# <EXTRACT XML FROM CAB FILE>
If(Test-Path "$ScriptDirectory\Files\$Computermodel\DellSDPCatalogPC.xml"){Remove-Item -Path "$ScriptDirectory\Files\$Computermodel\DellSDPCatalogPC.xml" -Force -Verbose}
Expand $CabPath "$ScriptDirectory\Files\$Computermodel" -f:*
# <IMPORT AND CREATE XML OBJECT>
If(Test-Path "$ScriptDirectory\Files\$Computermodel\DellSDPCatalogPC.xml"){[xml]$XML = Get-Content -Path "$ScriptDirectory\Files\$Computermodel\DellSDPCatalogPC.xml" -Verbose}
else{exit 15}
# <CREATE ARRAY OF DOWNLOADS>
$Downloads = $xml.SystemsManagementCatalog.SoftwareDistributionPackage
# <FIND TARGET DOWNLOAD FOR SPECIFIC DESIRED FUNCTION EXAMPLE>
$Model = ((Get-WmiObject win32_computersystem).Model).TrimEnd()
If (((($Model -match '7290') -or ($Model -match '7390') -or ($Model -match '7490')) -and (!($Model.EndsWith("AIO")) -or !($Model.EndsWith("M"))))){
$Target = $Downloads | Where-Object -FilterScript {
$PSitem.LocalizedProperties.Title -match '7290/7390/7490' -and $PSitem.LocalizedProperties.Title -notmatch $model + " AIO" -and $PSitem.LocalizedProperties.Title -notmatch $model + "M"
}
}
ElseIf (((($Model -match '7280') -or ($Model -match '7380') -or ($Model -match '7480')) -and (!($Model.EndsWith("AIO")) -or !($Model.EndsWith("M"))))){
$Target = $Downloads | Where-Object -FilterScript {
$PSitem.LocalizedProperties.Title -match '7280/7380/7480' -and $PSitem.LocalizedProperties.Title -notmatch $model + " AIO" -and $PSitem.LocalizedProperties.Title -notmatch $model + "M"
}
}
ElseIf (($Model.Contains("7080")) -and ((!($Model.EndsWith("AIO")) -or !($Model.EndsWith("M"))))){
$Target = $Downloads | Where-Object -FilterScript {
$PSitem.LocalizedProperties.Title -match "7080" -and $PSitem.LocalizedProperties.Title -notmatch $model + " AIO" -and $PSitem.LocalizedProperties.Title -notmatch $model + "M"
}
}
Else{$Target = $Downloads | Where-Object -FilterScript {$PSitem.LocalizedProperties.Title -match $model -and $PSitem.Properties.PublicationState -match "Published"}}
$TargetLink = $Target.InstallableItem.OriginFile.OriginUri
$TargetFileName = $Target.InstallableItem.OriginFile.FileName
Invoke-WebRequest -Uri $TargetLink -OutFile "$scriptDirectory\Files\$ComputerModel\$TargetFileName" -UseBasicParsing -Verbose
$File = "$scriptDirectory\Files\$ComputerModel\$TargetFileName"
# <SET COMMAND ARGUMENTS FOR BIOS UPDATE>
$cmds = "/s"
# <UPDATE BIOS>
execute-process -Path "$scriptDirectory\Files\$ComputerModel\$TargetFileName" $cmds -PassThru -wait
Thaaaanks!