$outlookApplication = New-Object -ComObject ‘Outlook.Application’
$profileName = $outlookApplication.Application.DefaultProfileName
$profileRoot16 = “HKCU:\Software\Microsoft\Office\16.0\Outlook\Profiles”
$profileRoot15 = “HKCU:\Software\Microsoft\Office\15.0\Outlook\Profiles”
if (Test-Path $profileRoot15){
$outlookProfile15 = Join-Path -Path $profileRoot15 -Childpath $profileName
}
if (Test-Path $profileRoot16){
$outlookProfile16 = Join-Path -Path $profileRoot16 -Childpath $profileName
}
if (-not(test-path $Env:USERPROFILE\outlookprofiledelete.log)){
if (test-path $profileRoot15){
Remove-Item “$outlookProfile15\*” -force -Recurse | Out-File $Env:USERPROFILE\outlookprofiledelete.log
}
if (test-path $profileRoot16){
Remove-Item “$outlookProfile16\*” -force -Recurse | Out-File $Env:USERPROFILE\outlookprofiledelete.log
}
}