If (Get-ScheduledTask -TaskName "*Daily Restart*" -EA SilentlyContinue){Get-ScheduledTask -TaskName "*Daily Restart*" | Unregister-ScheduledTask -Confirm:$False} If (Get-ScheduledTask -TaskName "*Update Apps*" -EA SilentlyContinue){Get-ScheduledTask -TaskName "*Update Apps*" | Unregister-ScheduledTask -Confirm:$False} Function Remove-PathForcefully { param( [parameter(Mandatory=$true)] [string] $Path ) Add-Type -ErrorAction Ignore @' using System; using System.Text; using System.Runtime.InteropServices; public class Posh { public enum MoveFileFlags { MOVEFILE_DELAY_UNTIL_REBOOT = 0x00000004 } [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, MoveFileFlags dwFlags); public static bool MarkFileDelete (string sourcefile) { return MoveFileEx(sourcefile, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT); } } '@ Function Remove-SubPath { param( [parameter(Mandatory=$true)] [string] $SubPath ) $SubPath = (Resolve-Path $SubPath -ErrorAction Stop).Path try { Remove-Item $SubPath -Force -Recurse -ErrorAction Stop Write-Host -ForegroundColor Green -BackgroundColor Black "Deletion of $SubPath succeeded." } catch { $deleteResult = [Posh]::MarkFileDelete($SubPath) if ($deleteResult -eq $false) { throw (New-Object ComponentModel.Win32Exception) # calls GetLastError } else { Write-Host -ForegroundColor Red -BackgroundColor Yellow "Deletion of ||$SubPath|| failed. Deleting at next boot."#`n$($_.Exception.Message)" } } } If (Test-Path -Path $Path -Verbose) { $SubFiles = Get-ChildItem -Path $Path -Recurse -Force -File $SubFolders = Get-ChildItem -Path $Path -Recurse -Force -Directory If ($SubFiles -or $SubFolders) { $SubFiles | ForEach-Object {Remove-SubPath -SubPath $_.FullName} $SubFolders | ForEach-Object {Remove-SubPath -SubPath $_.FullName} Remove-SubPath -SubPath $Path } Else { Remove-SubPath -SubPath $Path } } Else { Write-Warning "$Path was not found." } } Function Uninstall-Application { <# .SYNOPSIS Uninstall Application .DESCRIPTION Allows to Uninstall Application from system .EXAMPLE Uninstall-Application -AppToUninstall "Microsoft Office 2010 Primary Interop Assemblies" .PARAMETER AppToUninstall Application name (Or application name format) #> param( [Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='Enter the Application to uninstall.')] [Alias('Application')] [string] $AppToUninstall ) Write-Host '[Scanning All App sources]' Write-Host '--[Scanning Wmi Repository]' $Global:WmiApps = (Get-WmiObject -Class Win32_Product).Name | Select-Object -Unique | Sort-Object Write-Host '--[Scanning Native Powershell Repository]' $Global:PowershellApps = (Get-Package -Provider Programs -IncludeWindowsInstaller).Name | Select-Object -Unique | Sort-Object Write-Host '--[Scanning MSIExec UninstallString Repository]' $Global:uninstallX86RegPath="HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | Select-Object -Unique | Sort-Object $Global:uninstallX64RegPath="HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | Select-Object -Unique | Sort-Object $Global:MsiApps = (Get-ChildItem $uninstallX86RegPath | ForEach-Object { Get-ItemProperty $_.PSPath }).DisplayName $MsiApps += (Get-ChildItem $uninstallX64RegPath | ForEach-Object { Get-ItemProperty $_.PSPath }).DisplayName $Global:AllApps = $WmiApps + $PowershellApps + $MsiApps | Select-Object -Unique | Sort-Object $Global:Uninstalled = $False Function Uninstall-WmiApp { Write-Host -NoNewLine "Attempting Wmi method. " $AppWmi = Get-WmiObject -Class Win32_Product -ErrorAction SilentlyContinue | Where-Object {$_.Name -match $AppToUninstall} If ($AppWmi) { If ($AppWmi) { $AppWmi.Uninstall() $AppWmi = Get-WmiObject -Class Win32_Product -ErrorAction SilentlyContinue | Where-Object {$_.Name -match $AppToUninstall} } If (-not $AppWmi) { Write-Host -ForegroundColor Green "$AppToUninstall appears to have been successfully uninstalled via Wmi method." $Global:Uninstalled = $True } Else { Write-Host -ForegroundColor Yellow "Uninstalling via `(Get-WmiObject`).Uninstall`(`) method didn`'t work." } } } Function Uninstall-PowershellApp { Write-Host -NoNewLine "Attempting Uninstall-Package method. " Get-Package -Provider Programs -IncludeWindowsInstaller | Where-Object -Property 'Name' -Match $AppToUninstall | Uninstall-Package -Force -AllVersions If (-not (Get-Package -Provider Programs -IncludeWindowsInstaller | Where-Object -Property 'Name' -Match $AppToUninstall)){ Write-Host -ForegroundColor Green "$AppToUninstall appears to have been successfully uninstalled via Uninstall-Package method." $Global:Uninstalled = $True } Else { Write-Host -ForegroundColor Yellow "Uninstalling via Uninstall-Package method didn't work." } } Function Uninstall-MsiApp { Write-Host -NoNewLine "Attempting MSI UninstallString method. " $uninstallString="" $uninstall32 = (Get-ChildItem $uninstallX86RegPath | ForEach-Object { Get-ItemProperty $_.PSPath } | ? { $_ -Match $AppToUninstall }).UninstallString $uninstall64 = (Get-ChildItem $uninstallX64RegPath | ForEach-Object { Get-ItemProperty $_.PSPath } | ? { $_ -Match $AppToUninstall }).UninstallString If($uninstall64) {$uninstallString=$uninstall64} If($uninstall32) {$uninstallString=$uninstall32} If(!$uninstallString) { Write-Error "Application was is not found" } $uninstallString = $uninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X","" $uninstallString = $uninstallString.Trim() Start-Process "msiexec.exe" -arg "/X $uninstallString /qn" -Wait $MsiApps = (Get-ChildItem $uninstallX86RegPath | ForEach-Object { Get-ItemProperty $_.PSPath }).DisplayName $MsiApps += (Get-ChildItem $uninstallX64RegPath | ForEach-Object { Get-ItemProperty $_.PSPath }).DisplayName If (-not ($MsiApps -Match $AppToUninstall)) { Write-Host -ForegroundColor Green "$AppToUninstall appears to have been successfully uninstalled via MSI UninstallString method." $Global:Uninstalled = $True } Else { Write-Host -ForegroundColor Yellow "Uninstalling via Msi UninstallString method didn't work." } } If (-Not $AppToUninstall) { Write-Host "Review the applications available to uninstall, then enter it verbatim." Write-Host -ForegroundColor Yellow "Note: You can use the '-AppToUninstall' options to specify the app without interaction or pipe in the name." Pause $AllApps | More $AppToUninstall = Read-Host "App to Uninstall: " } If ($AppToUninstall){ If ($AllApps -Match $AppToUninstall) { Write-Host "$AppToUninstall found. Attempting uninstall. " If ($WmiApps -Match $AppToUninstall) {Uninstall-WmiApp} If ((-Not $Uninstalled) -and ($PowershellApps -Match $AppToUninstall)) {Uninstall-PowershellApp} If ((-Not $Uninstalled) -and ($MsiApps -Match $AppToUninstall)) {Uninstall-MsiApp} If (-Not $Uninstalled) {Write-Host -ForegroundColor Red "Uninstall Failed. Please try uninstalling via Windows Settings Menus."} } Else { Write-Host -ForegroundColor Yellow "$AppToUninstall was not found." } } Else { Write-Host -ForegroundColor Red "No application specified." } #Cleanup! @("WmiApps", "PowershellApps", "uninstallX86RegPath", "uninstallX64RegPath", "MsiApps", "AllApps", "Uninstalled") | ForEach-Object { Clear-Variable $_ -Force -ErrorAction SilentlyContinue } } Remove-PathForcefully -Path $Env:SystemDrive\Ambitions -ErrorAction SilentlyContinue Remove-PathForcefully -Path $Env:SystemDrive\Ambitions -ErrorAction SilentlyContinue If (Test-Path $PROFILE) {Remove-PathForcefully -Path $Profile -ErrorAction SilentlyContinue} $AppsToRemove = @( "Umbrella Roaming Client" "Webroot SecureAnywhere" "Dell Command" "LogMeIn Client" "ITSPlatform" "ITSupport247-DPMA" "ScreenConnect Client" ) ForEach ($app in $AppsToRemove) { Uninstall-Application -AppToUninstall $app -EA SilentlyContinue } Clear-History Clear-Host