I need to know the best why to remove a folder from a users profile. We have a problem with the Global Address List updating on user workstations. The network administrator solved his synching problem by deleting the Offline Address Books folder on his machine so I am now tasked with deleting folders on each workstation until a fix is found. I wrote a rough PowerShell script which either uses the workstation name to generate a specific user profile or I can target the logged on user.
I test whether Outlook is running and make sure Outlook is closed before I proceed. I also check to see if the folder exists and delete the folder before exiting. I want to make sure I can delete the folder without an error.
#Deriving the variables from the name of the computer. $Computer=$env:COMPUTERNAME $String = ("$Computer" -split'-')[0] $Length = $String.Length $FirstInitial = $String.Substring(0,1) $LastName = $String.Substring(1) $UserName = $LastName+$FirstInitial $Path = "C:\" + "\users" + "\$UserName" + "\AppData" + "\Local" + "\Microsoft" + "\Outlook" $OABPath = $Path + "\Offline Address Books" #Checking to see if Outlook is running. if (Get-Process -Name "Outlook" -ErrorAction SilentlyContinue | Where-Object {-not $_.HasExited }) { Stop-Process -Name "Outlook" -Force Sleep -Seconds 30 } #Deleting the Offline Address Books folder if it exists. If(Test-Path -Path $OABPath) { $OAB = Get-ChildItem -Path $Path -Recurse $OAB | foreach { [io.directory]::delete($_.fullname) } }Any help would be appreciated. Thanks in advance.