Marli-OutlookReset.ps1

function Marli-OutlookReset {
 function New_Entry ([int]$xposi,[int]$yposi,[string]$Text,[System.ConsoleColor]$Color){
  $position=$Host.ui.RawUI.CursorPosition
  $position.x = $xposi
  $position.y = $yposi
  $Host.ui.RawUI.CursorPosition=$position
  Write-Host $Text -ForegroundColor $Color
 }
 
 Clear-Host
 Write-Host 'Reset Outlook-Profiles' -ForegroundColor Green
 Write-Host '----------------------'
 Write-Host ''
 Write-Host 'Close Outlook >------[ ]'
 Write-Host 'Remove Localfiles >--[ ]'
 Write-Host 'Remove Regkeys >-----[ ]'
 Write-Host 'Restart Outlook >----[ ]'
 Write-Host ''
 Read-Host -Prompt 'Press Enter to start...'
 ##########################################################
 New_Entry -xposi 0 -yposi 8 -Text ' ' -Color White
 
 # Stop Outlook #######################################
 New_Entry -xposi 22 -yposi 3 -Text '<-' -Color Yellow
 Stop-Process -Name *outlook* -Force -ErrorAction SilentlyContinue
 Start-Sleep -Seconds 1
 If (!(Get-Process -Name *Outlook*)) {
  New_Entry -xposi 22 -yposi 3 -Text 'ok' -Color Green
 }
 else {
  New_Entry -xposi 22 -yposi 3 -Text 'nA' -Color Red
  Read-Host
  Exit
 }
 
 # Remove Localfiles ##################################
 $LocalPath = "$env:LOCALAPPDATA\microsoft\outlook"
 New_Entry -xposi 22 -yposi 4 -Text '<-' -Color Yellow
 try{Remove-Item -Path $LocalPath -Force -Confirm:$false -Recurse -ErrorAction SilentlyContinue}catch{}
 Start-Sleep -Seconds 1
 If (!(Test-Path -Path $LocalPath)) {
  New_Entry -xposi 22 -yposi 4 -Text 'ok' -Color Green
 }
 else {
  New_Entry -xposi 22 -yposi 4 -Text 'nA' -Color Red
  Read-Host
  Exit
 }
 
 #Remove Regkeys
 New_Entry -xposi 22 -yposi 5 -Text '<-' -Color Yellow
 $VersionList = (Get-Childitem -Path 'HKCU:\SOFTWARE\Microsoft\Office') | select -ExpandProperty PSChildName

 Foreach ($Version in $VersionList) {
  If ($Version -match '\d') {
   $RegPath = "HKCU:\SOFTWARE\Microsoft\Office\$Version\Outlook\Profiles\Outlook"
   try{Remove-Item -Path $RegPath -Force -Recurse -ErrorAction SilentlyContinue}catch{}
   Start-Sleep -Seconds 1
   If (!(Test-Path -Path $RegPath)) {
    New_Entry -xposi 22 -yposi 5 -Text 'ok' -Color Green
   }
   else {
    New_Entry -xposi 22 -yposi 5 -Text 'nA' -Color Red
    Read-Host
    Exit
   }
  }
 }

 
 # Restart Outlook ####################################
 New_Entry -xposi 22 -yposi 6 -Text '<-' -Color Yellow
 Try{
  Start-Process Outlook
  Start-Sleep -Seconds 1
  New_Entry -xposi 22 -yposi 6 -Text 'ok' -Color Green
 }
 catch{
   New_Entry -xposi 22 -yposi 6 -Text 'nA' -Color Red
   Read-Host
   Exit
 }
}