Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Define log file
- $LogFile = "C:\temp\outlookremovalv2.txt"
- # Ensure temp directory exists
- if (!(Test-Path -Path "C:\temp")) {
- New-Item -ItemType Directory -Path "C:\temp"
- }
- # Function to log messages
- function Log {
- param ([string]$Message)
- $Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
- "$Timestamp : $Message" | Out-File -FilePath $LogFile -Append
- }
- # 1. Check for OutlookUpdate value and delete it
- $KeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe"
- $ValueName = "OutlookUpdate"
- Log "Checking for $ValueName in $KeyPath"
- $Value = reg query $KeyPath /v $ValueName 2>&1
- if ($Value -match $ValueName) {
- Log "$ValueName exists. Attempting to delete."
- reg delete $KeyPath /v $ValueName /f
- if ($?) {
- Log "$ValueName deleted successfully."
- } else {
- Log "Failed to delete $ValueName."
- }
- } else {
- Log "$ValueName does not exist."
- }
- # 2. Enumerate ProfileList and modify specific keys
- $ProfileListKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
- Log "Enumerating profiles in $ProfileListKey"
- $Profiles = reg query $ProfileListKey
- $Profiles -split "\r?\n" | ForEach-Object {
- if ($_ -match "S-1-5-21-\d+-\d+-817656539-(?!500$)\d+$") {
- $SID = $_ -replace "\s+$", ""
- Log "Found matching profile: $SID"
- $GeneralKey = "$SID\Software\Microsoft\Office\16.0\Outlook\Options\General"
- Log "Checking and setting HideNewOutlookToggle in $GeneralKey"
- if (reg query $GeneralKey /v HideNewOutlookToggle 2>&1 | Out-String | Select-String -NotMatch "The system was unable to find the specified registry key or value") {
- reg add $GeneralKey /v HideNewOutlookToggle /t REG_DWORD /d 00000000 /f
- } else {
- reg add $GeneralKey /v HideNewOutlookToggle /t REG_DWORD /d 00000000 /f
- }
- Log "Checking and setting DoNewOutlookAutoMigration in $GeneralKey"
- if (reg query $GeneralKey /v DoNewOutlookAutoMigration 2>&1 | Out-String | Select-String -NotMatch "The system was unable to find the specified registry key or value") {
- reg add $GeneralKey /v DoNewOutlookAutoMigration /t REG_DWORD /d 00000000 /f
- } else {
- reg add $GeneralKey /v DoNewOutlookAutoMigration /t REG_DWORD /d 00000000 /f
- }
- Log "Checking and setting NewOutlookAutoMigrationRetryIntervals in $GeneralKey"
- if (reg query $GeneralKey /v NewOutlookAutoMigrationRetryIntervals 2>&1 | Out-String | Select-String -NotMatch "The system was unable to find the specified registry key or value") {
- reg add $GeneralKey /v NewOutlookAutoMigrationRetryIntervals /t REG_DWORD /d 00000000 /f
- } else {
- reg add $GeneralKey /v NewOutlookAutoMigrationRetryIntervals /t REG_DWORD /d 00000000 /f
- }
- $PreferencesKey = "$SID\Software\Microsoft\Office\16.0\Outlook\preferences"
- Log "Checking and setting NewOutlookMigrationUserSetting in $PreferencesKey"
- if (reg query $PreferencesKey /v NewOutlookMigrationUserSetting 2>&1 | Out-String | Select-String -NotMatch "The system was unable to find the specified registry key or value") {
- reg add $PreferencesKey /v NewOutlookMigrationUserSetting /t REG_DWORD /d 00000000 /f
- } else {
- reg add $PreferencesKey /v NewOutlookMigrationUserSetting /t REG_DWORD /d 00000000 /f
- }
- }
- }
- # 3. Remove Outlook and related packages
- Log "Removing Microsoft OutlookForWindows packages"
- try {
- $OutlookPackage = Get-AppxPackage Microsoft.OutlookForWindows -ErrorAction Stop
- Remove-AppxProvisionedPackage -AllUsers -Online -PackageName $OutlookPackage.PackageFullName
- Remove-AppxPackage -AllUsers -Package $OutlookPackage.PackageFullName
- Log "OutlookForWindows package removed successfully."
- } catch {
- Log "Error removing OutlookForWindows package: $_"
- }
- Log "Removing Windows Communications Apps"
- try {
- Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -match "microsoft.windowscommunicationsapps"} | ForEach-Object {
- Remove-AppxProvisionedPackage -Online -PackageName $_.PackageName
- }
- Get-AppxPackage microsoft.windowscommunicationsapps | ForEach-Object {
- Remove-AppxPackage -AllUsers -Package $_.PackageFullName
- }
- Log "Windows Communications Apps removed successfully."
- } catch {
- Log "Error removing Windows Communications Apps: $_"
- }
- # 4. Remove New Outlook from taskbar
- $appname1 = "Outlook (New)"
- Log "Attempting to unpin $appname1 from taskbar"
- try {
- ((New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items() | ?{$_.Name -eq $appname1}).Verbs() | ?{$_.Name.replace('&','') -match 'Unpin from taskbar'} | %{$_.DoIt(); $exec = $true}
- if ($exec) {
- Log "$appname1 successfully unpinned from taskbar."
- } else {
- Log "$appname1 was not found on taskbar or could not be unpinned."
- }
- } catch {
- Log "Error unpinning $appname1 from taskbar: $_"
- }
- Log "Script execution completed."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement