PSScripts/Delete-Temp&Sage200Folder.ps1

33 lines
1.0 KiB
PowerShell
Raw Normal View History

2023-12-18 18:00:56 +00:00
#Sets Execution Policy to allow script to run
Set-ExecutionPolicy -Scope CurrentUser -Force Unrestricted -Confirm:$False
#start-sleep -Seconds 10
#Sets current user name to varible, converts to string, finds index of "\", adds 1 to get the index of the first character in name
$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$user.ToString()
$i = $user.IndexOf("\")
$i+=1
#Creates blank string varible
$userNew = ""
#For loop to start at the index of first character of username and end at the length of the username
for ($i; $i -lt $user.Length; $i++)
{
$userNew = $userNew + $user[$i] #adds the indexed character to new varible
}
$userNew
$TempFolder = "C:\Users\"+$userNew+"\AppData\Local\Temp\"
$SageFolder = "C:\Users\"+$userNew+"\AppData\Local\Sage\Sage200\"
Get-ChildItem $TempFolder | Remove-Item -Recurse -Force
Get-ChildItem $SageFolder | Remove-Item -Recurse -Force
#start-sleep -Seconds 10
Set-ExecutionPolicy -Scope CurrentUser -Force Undefined -Confirm:$False
#start-sleep -Seconds 20