Files

83 lines
3.2 KiB
PowerShell

#Define Variables
$ts = new-object -comobject microsoft.sms.tsenvironment
$ErrorReturnCode = $ts.value("_SMSTSLastActionSucceeded")
$UpgradeErrorReturnCode = $ts.value("_SMSTSLastActionRetCode")
$My_DeployRoot = $ts.value("DeployRoot")
$Step_Lang = $ts.value("Item_Name")
$Step_Version = $ts.value("Item_Version")
$Computer_Name = $ts.value("MyComputer")
$exeName = ""
$srcDir = $My_DeployRoot + "\Scripts\BIOSUpgrade\Lenovo\"
$localBiosFolder = "X:\bios"
$csproduct = Get-WmiObject -Class Win32_ComputerSystemProduct -Namespace root\cimv2
$deviceID = $csproduct.Name + '-' + $csproduct.IdentifyingNumber
$type = $csproduct.Version.Split()[0]
$model = $csproduct.Version.Split(' ', 2)[1]
$osArc = (Get-WmiObject -Class Win32_OperatingSystem -Namespace root\cimv2).OSArchitecture
$BiosCode = (Get-WmiObject -Class Win32_BIOS -Namespace root\cimv2).SMBIOSBIOSVersion.Substring(0,4)
$log = $srcDir + 'logs\' + $deviceID + '.log'
#Locate and Copy BIOS Folder
Write-Host "Locating BIOS folder"
$folder = Get-ChildItem -Path $srcDir | ? {$_.Name -eq $BiosCode}
if($folder -eq $null)
{
"Could not find folder for $deviceID. Looking for $BiosCode" | out-file $log
Write-Host "Could not locate BIOS folder"
Write-Host "Examine log file on the share for more information"
return
}
Write-Host "Located BIOS folder"
Write-Host "Begin BIOS Files Copy"
Copy-Item ($srcDir + $folder + '\*') $localBiosFolder -Recurse
Write-Host "Completed BIOS Files Copy"
#Execute BIOS Flash and Reboot
Write-Host "Executing BIOS Flash"
If($type -eq "ThinkPad")
{
$exeName = if($osArc -eq "32-bit") {"WINUPTP.EXE"} else {"WINUPTP64.EXE"}
$arg1 = "-s"
& .\$exeName $arg1 | Out-Null
If (Test-Path $localBiosFolder\winuptp.log)
{
Copy-Item $localBiosFolder\winuptp.log $log # Copy the log file for this device to the network share for auditing purposes.
}
Else
{
"Could not find log file for $deviceID" | out-file $log
Write-Host "Could not locate Winuptp.log file"
}
Write-Host "Completing BIOS Flash..."
Write-Host "..."
Write-Host "Rebooting"
& "wpeutil" reboot
}
ElseIf($type -eq "ThinkCentre" -or ($type -eq "ThinkStation" -and $model -like "P3*"))
{
& ".\Flash.cmd" /ign /sccm /quiet | Out-File $log # Check the readme.txt to ensure that each WFlash2.exe supports the /SCCM (Reboot Suppress) switch.
Write-Host "Completing BIOS Flash..."
Write-Host "..."
Write-Host "Rebooting"
& "wpeutil" shutdown # This needs to be a shutdown command, as the ThinkCentre BIOS documentation states
# that the computer needs to reach an S5 power state to complete the update of the
# BIOS. Computer will actually reboot.
}
ElseIf($type -eq "ThinkStation")
{
$exeName = if($osArc -eq "32-bit") {"AFUWIN.EXE"} else {"AFUWINx64.EXE"}
$ROMName = Get-ChildItem -Path $localBiosFolder -Include "*.ROM" -Name
& .\$exeName $ROMName /P /B /N /R /SP /RTB /FIT | Out-File $log
Write-Host "Completing BIOS Flash..."
Write-Host "..."
Write-Host "Rebooting"
& "wpeutil" reboot
}
Else
{
"Unable to determine type of machine for $deviceID" | out-file $log
Write-Host "Unable to determine type of machine for $deviceID"
}