Powershell to Delete Outlook Profiles
-
I am trying to get this script to work. End result is to have it check to see if there is a file that exists, that we will push out with RMM.
If that files DOES exist Start script, if that file does not exist, Exit. Do not pass GO and collect 200.
Then once that check is done, see if there is a done file, if file exists, quit, if file is missing GO!#Run on system logged in as the user you are trying to delete and recreate the profile for
Set-ExecutionPolicy Unrestricted currentuser
#Environment Check, if 'profdelcheck' file exist, run script. If File does not exist, quit script.
#This file will be pushed out by RMM to machines needing the change.
if(Test-Path "C:\windows\temp\profdelcheck.txt")
{
Else Exit
}#Environment Check, if Done file exist, quit script, if file does not exist run script.
if(Test-Path "$Env:appdata\Microsoft\Outlook\done.txt")
{
Else Exit
}#Only enable this section if risk of deleting all OST's and possible PST's that might be there are acceptable.
#if(Test-Path "$Env:appdata\Microsoft\Outlook")
{
#Remove-Item "$Env:appdata\Microsoft\Outlook" -force -recurse
}##Checks to See 2010 is installed and will run for 2010##
if(Test-Path HKCU:\Software\Microsoft\Office\14.0\Outlook)
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Office\14.0\Outlook\AutoDiscover -Name ZeroConfigExchange -Value 1 -PropertyType DWORD -ForceRemove-Item "HKCU:\Software\Microsoft\Office\14.0\Outlook\Profiles*" -Recurse -Force
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Office\14.0\Outlook\Setup\ -name First-Run
cd 'C:\Program Files (x86)\Microsoft Office\Office14'
.\outlook.exe
#Now will create a done file
New-Item -path '$Env:appdata\Microsoft\Outlook' -Name done.txt -Value 'Outlook 2010 data cleared for user' -ItemType file -force}
##Checks to See 2013 is installed and will run for 2013#
if(Test-Path HKCU:\Software\Microsoft\Office\15.0\Outlook)
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Office\15.0\Outlook\AutoDiscover -Name ZeroConfigExchange -Value 1 -PropertyType DWORD -ForceRemove-Item "HKCU:\Software\Microsoft\Office\15.0\Outlook\Profiles*" -Recurse -Force
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Office\15.0\Outlook\Setup\ -name First-Run
cd 'C:\Program Files (x86)\Microsoft Office\Office15'
.\outlook.exe
#Now will create a done file
New-Item -path '$Env:appdata\Microsoft\Outlook' -Name done.txt -Value 'Outlook 2013 data cleared for user' -ItemType file -force}
##Checks to See 2016 is installed and will run for 2016##
if(Test-Path HKCU:\Software\Microsoft\Office\16.0\Outlook)
{
New-ItemProperty -Path HKCU:\Software\Microsoft\Office\16.0\Outlook\AutoDiscover -Name ZeroConfigExchange -Value 1 -PropertyType DWORD -ForceRemove-Item "HKCU:\Software\Microsoft\Office\16.0\Outlook\Profiles*" -Recurse -Force
Remove-ItemProperty -Path HKCU:\Software\Microsoft\Office\16.0\Outlook\Setup\ -name First-Run
cd 'C:\Program Files (x86)\Microsoft Office\Office16'
.\outlook.exe
#Now will create a done file
New-Item -path '$Env:appdata\Microsoft\Outlook' -Name done.txt -Value 'Outlook 2016 data cleared for user' -ItemType file -force}