Skip to content

Commit

Permalink
Added Error Checking
Browse files Browse the repository at this point in the history
Added error checking to verify if Dell Command | Update is installed and to exit with an error code one if not.
  • Loading branch information
mickpletcher authored Nov 18, 2019
1 parent 2a46ac2 commit 2c24f62
Showing 1 changed file with 42 additions and 27 deletions.
69 changes: 42 additions & 27 deletions ZTIDellDriverUpdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,52 @@
#>
[CmdletBinding()]
param ()
#Delete old logs if they exist
Remove-Item -Path ($env:windir + '\temp\ActivityLog.xml') -ErrorAction SilentlyContinue -Force
Remove-Item -Path ($env:windir + '\temp\inventory.xml') -ErrorAction SilentlyContinue -Force
#Update the system with the latest drivers while also writing log files to the %windir%\temp directory
$ErrCode = (Start-Process -FilePath ((Get-ChildItem -Path $env:ProgramFiles, ${env:ProgramFiles(x86)} -Filter 'dcu-cli.exe' -Recurse).FullName) -ArgumentList ('/log ' + $env:windir + '\temp') -Wait).ExitCode
#Read the ActivityLog.xml file
$File = (Get-Content -Path ($env:windir + '\temp\ActivityLog.xml')).Trim()
#if no updates were found or updates were applied and no required reboot is necessary, then delete the log files
If (('<message>CLI: No application component updates found.</message>' -in $File) -and (('<message>CLI: No available updates can be installed.</message>' -in $File) -or ('<message>CLI: No updates are available.</message>' -in $File))) {

#Verify Dell Command | Update exists
If ((Test-Path -Path (Get-ChildItem -Path $env:ProgramFiles, ${env:ProgramFiles(x86)} -filter dcu-cli.exe -Recurse -ErrorAction SilentlyContinue).FullName) -eq $true) {
#Delete old logs if they exist
Remove-Item -Path ($env:windir + '\temp\ActivityLog.xml') -ErrorAction SilentlyContinue -Force
Remove-Item -Path ($env:windir + '\temp\inventory.xml') -ErrorAction SilentlyContinue -Force
Remove-Item -Path ($env:TEMP + '\RebootCount.log') -ErrorAction SilentlyContinue -Force
} else {
#Create the file containing number of times this script has rerun if it does not exist
If ((Test-Path ($env:TEMP + '\RebootCount.log')) -eq $false) {
New-Item -Path ($env:TEMP + '\RebootCount.log') -ItemType File -Value 0 -Force
}
#Reboot the machine and rerun the Dell Driver Updates
If (([int](Get-Content -Path ($env:TEMP + '\RebootCount.log'))) -lt 5) {
#Microsoft SCCM/MDT environmental variables
$TSEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment
#Reboot the machine once this task is completed and restart the task sequence
$TSEnv.Value('SMSTSRebootRequested') = $true
#Rerun the same task
$TSEnv.Value('SMSTSRetryRequested') = $true
#increment the reboot counter
New-Item -Path ($env:TEMP + '\RebootCount.log') -ItemType File -Value ([int](Get-Content -Path ($env:TEMP + '\RebootCount.log')) + 1) -Force
#End the update process if run 5 or more times, delete all associated log files, and proceed to the next task
} else {
#Update the system with the latest drivers while also writing log files to the %windir%\temp directory
$ErrCode = (Start-Process -FilePath ((Get-ChildItem -Path $env:ProgramFiles, ${env:ProgramFiles(x86)} -Filter 'dcu-cli.exe' -Recurse).FullName) -ArgumentList ('/log ' + $env:windir + '\temp') -Wait).ExitCode
#Read the ActivityLog.xml file
$File = (Get-Content -Path ($env:windir + '\temp\ActivityLog.xml')).Trim()
#if no updates were found or updates were applied and no required reboot is necessary, then delete the log files
If (('<message>CLI: No application component updates found.</message>' -in $File) -and (('<message>CLI: No available updates can be installed.</message>' -in $File) -or ('<message>CLI: No updates are available.</message>' -in $File)))
{
Remove-Item -Path ($env:windir + '\temp\ActivityLog.xml') -ErrorAction SilentlyContinue -Force
Remove-Item -Path ($env:windir + '\temp\inventory.xml') -ErrorAction SilentlyContinue -Force
Remove-Item -Path ($env:TEMP + '\RebootCount.log') -ErrorAction SilentlyContinue -Force
}
else
{
#Create the file containing number of times this script has rerun if it does not exist
If ((Test-Path ($env:TEMP + '\RebootCount.log')) -eq $false)
{
New-Item -Path ($env:TEMP + '\RebootCount.log') -ItemType File -Value 0 -Force
}
#Reboot the machine and rerun the Dell Driver Updates
If (([int](Get-Content -Path ($env:TEMP + '\RebootCount.log'))) -lt 5)
{
#Microsoft SCCM/MDT environmental variables
$TSEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment
#Reboot the machine once this task is completed and restart the task sequence
$TSEnv.Value('SMSTSRebootRequested') = $true
#Rerun the same task
$TSEnv.Value('SMSTSRetryRequested') = $true
#increment the reboot counter
New-Item -Path ($env:TEMP + '\RebootCount.log') -ItemType File -Value ([int](Get-Content -Path ($env:TEMP + '\RebootCount.log')) + 1) -Force
#End the update process if run 5 or more times, delete all associated log files, and proceed to the next task
}
else
{
Remove-Item -Path ($env:windir + '\temp\ActivityLog.xml') -ErrorAction SilentlyContinue -Force
Remove-Item -Path ($env:windir + '\temp\inventory.xml') -ErrorAction SilentlyContinue -Force
Remove-Item -Path ($env:TEMP + '\RebootCount.log') -ErrorAction SilentlyContinue -Force
}
}
}
else {
Write-Output 'Dell Command | Update is not installed'
Exit 1
}

0 comments on commit 2c24f62

Please sign in to comment.