Hi,
I’m writing a script to uninstall windows ADK 8.1 and install ADK 10.
This function is to uninstall ADK 8.1. I would really value people’s opinion on the script and improvements or shortcuts. Thanks !
#region Uninistall AKD 8.1
Function Uninstall-ADK8.1 { #Step 1 check for existing install of Windows ADK 8.1
[CmdletBinding(SupportsShouldProcess=$True,
ConfirmImpact='High')]
Param
(
)
Begin
{
write-verbose "This function will check for a install of Windows ADK 8.1 and unistall if `nThis is to prepare for Install of Windows 10 ADK"
}
Process
{ #Test for existing Install of Windows ADK 8.1
if (test-path 'C:\Program Files (x86)\Windows Kits\8.1')
{
#Find ADKsetup.exe in C:\ProgramData\Package Cache for uninstall
$UninstallFolder = dir 'C:\ProgramData\Package Cache\' -Filter "adksetup*" -Recurse
if ($UninstallFolder -ne $null) #.Exists gives a boolean result
{
Write-Verbose "file found"
}
else {
Write-Warning "ADKSetup to uninstall ADK 10 not found`n`n Terminating Uninstall process"
break
}
#Perform Uninstall
Write-Verbose "Windows ADK 10 exists on this machine, will uninstall`n"
write-warning ": Uninstalling ADK 8.1 ....."
Start-Process $($UninstallFolder.FullName) -ArgumentList '/quiet /uninstall /norestart' -Wait
Write-Verbose "Uninstall complete, will clean up any existing folders....."
#Perform check and removal of folder
#Set folder variables
$folder = 'C:\Program Files (x86)\Windows Kits\8.1'
$check = $folder | Test-Path
#Run Check
@{$true = Remove-Item -Path $folder -Recurse -Force -ErrorAction SilentlyContinue; $false = 'Folder does not exist'}[$check -eq $true]
##
write-verbose "Done`n"
}
else #No action required
{
Write-Verbose "No install of Windows ADK 8.1 in this machine"
}
}
End
{
Write-Verbose "Ready for Install of ADK 10"
}
}
#endregion