Advertisement
Guest User

Untitled

a guest
Jan 15th, 2025
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. # Define log file
  2. $LogFile = "C:\temp\outlookremovalv2.txt"
  3. # Ensure temp directory exists
  4. if (!(Test-Path -Path "C:\temp")) {
  5. New-Item -ItemType Directory -Path "C:\temp"
  6. }
  7.  
  8. # Function to log messages
  9. function Log {
  10. param ([string]$Message)
  11. $Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
  12. "$Timestamp : $Message" | Out-File -FilePath $LogFile -Append
  13. }
  14.  
  15. # 1. Check for OutlookUpdate value and delete it
  16. $KeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe"
  17. $ValueName = "OutlookUpdate"
  18. Log "Checking for $ValueName in $KeyPath"
  19. $Value = reg query $KeyPath /v $ValueName 2>&1
  20. if ($Value -match $ValueName) {
  21. Log "$ValueName exists. Attempting to delete."
  22. reg delete $KeyPath /v $ValueName /f
  23. if ($?) {
  24. Log "$ValueName deleted successfully."
  25. } else {
  26. Log "Failed to delete $ValueName."
  27. }
  28. } else {
  29. Log "$ValueName does not exist."
  30. }
  31.  
  32. # 2. Enumerate ProfileList and modify specific keys
  33. $ProfileListKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
  34. Log "Enumerating profiles in $ProfileListKey"
  35. $Profiles = reg query $ProfileListKey
  36. $Profiles -split "\r?\n" | ForEach-Object {
  37. if ($_ -match "S-1-5-21-\d+-\d+-817656539-(?!500$)\d+$") {
  38. $SID = $_ -replace "\s+$", ""
  39. Log "Found matching profile: $SID"
  40.  
  41. $GeneralKey = "$SID\Software\Microsoft\Office\16.0\Outlook\Options\General"
  42. Log "Checking and setting HideNewOutlookToggle in $GeneralKey"
  43. 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") {
  44. reg add $GeneralKey /v HideNewOutlookToggle /t REG_DWORD /d 00000000 /f
  45. } else {
  46. reg add $GeneralKey /v HideNewOutlookToggle /t REG_DWORD /d 00000000 /f
  47. }
  48.  
  49. Log "Checking and setting DoNewOutlookAutoMigration in $GeneralKey"
  50. 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") {
  51. reg add $GeneralKey /v DoNewOutlookAutoMigration /t REG_DWORD /d 00000000 /f
  52. } else {
  53. reg add $GeneralKey /v DoNewOutlookAutoMigration /t REG_DWORD /d 00000000 /f
  54. }
  55.  
  56. Log "Checking and setting NewOutlookAutoMigrationRetryIntervals in $GeneralKey"
  57. 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") {
  58. reg add $GeneralKey /v NewOutlookAutoMigrationRetryIntervals /t REG_DWORD /d 00000000 /f
  59. } else {
  60. reg add $GeneralKey /v NewOutlookAutoMigrationRetryIntervals /t REG_DWORD /d 00000000 /f
  61. }
  62.  
  63. $PreferencesKey = "$SID\Software\Microsoft\Office\16.0\Outlook\preferences"
  64. Log "Checking and setting NewOutlookMigrationUserSetting in $PreferencesKey"
  65. 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") {
  66. reg add $PreferencesKey /v NewOutlookMigrationUserSetting /t REG_DWORD /d 00000000 /f
  67. } else {
  68. reg add $PreferencesKey /v NewOutlookMigrationUserSetting /t REG_DWORD /d 00000000 /f
  69. }
  70. }
  71. }
  72.  
  73. # 3. Remove Outlook and related packages
  74. Log "Removing Microsoft OutlookForWindows packages"
  75. try {
  76. $OutlookPackage = Get-AppxPackage Microsoft.OutlookForWindows -ErrorAction Stop
  77. Remove-AppxProvisionedPackage -AllUsers -Online -PackageName $OutlookPackage.PackageFullName
  78. Remove-AppxPackage -AllUsers -Package $OutlookPackage.PackageFullName
  79. Log "OutlookForWindows package removed successfully."
  80. } catch {
  81. Log "Error removing OutlookForWindows package: $_"
  82. }
  83.  
  84. Log "Removing Windows Communications Apps"
  85. try {
  86. Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -match "microsoft.windowscommunicationsapps"} | ForEach-Object {
  87. Remove-AppxProvisionedPackage -Online -PackageName $_.PackageName
  88. }
  89. Get-AppxPackage microsoft.windowscommunicationsapps | ForEach-Object {
  90. Remove-AppxPackage -AllUsers -Package $_.PackageFullName
  91. }
  92. Log "Windows Communications Apps removed successfully."
  93. } catch {
  94. Log "Error removing Windows Communications Apps: $_"
  95. }
  96.  
  97. # 4. Remove New Outlook from taskbar
  98. $appname1 = "Outlook (New)"
  99. Log "Attempting to unpin $appname1 from taskbar"
  100. try {
  101. ((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}
  102. if ($exec) {
  103. Log "$appname1 successfully unpinned from taskbar."
  104. } else {
  105. Log "$appname1 was not found on taskbar or could not be unpinned."
  106. }
  107. } catch {
  108. Log "Error unpinning $appname1 from taskbar: $_"
  109. }
  110.  
  111. Log "Script execution completed."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement