Skip to content

Commit 14691b7

Browse files
committed
Added delete temporary files function
1 parent 0d34679 commit 14691b7

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

optimize.ps1

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,26 @@ if ( $userinput -eq 'y' -or !$userinput ) {
6868
$Services = Get-Content .\Config\services.json | ConvertFrom-Json
6969

7070
for ($i = 0; $i -lt $Services.service.name.Count; $i++) {
71-
$Services.service.name[$i] | Set-Service -StartupType $Services.service.StartupType[$i] | Out-Null
71+
$Services.service.name[$i] | Set-Service -StartupType $Services.service.StartupType[$i] -ErrorAction SilentlyContinue
7272
}
7373

7474
Write-Output "
75+
If you see any errors stating ""Service wasn't found"" or ""Access is denied,"" don't worry, nothing is wrong.
76+
"
77+
}
78+
79+
# Delete C:\Windows\Temp and user's temporary files
80+
$userinput = Read-Host -Prompt 'Do you want to delete temporary files (Recommended) (Y/n)'
81+
if ( $userinput -eq 'y' -or !$userinput ) {
82+
Write-Output "Removing Windows Temporary Files (C:\Windows\Temp)"
83+
Start-Sleep 1
84+
Get-ChildItem -Path "C:\Windows\Temp" *.* -Recurse | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
7585

76-
If you see any errors stating Service wasn't found or Access is denied, don't worry, nothing is wrong."
86+
Write-Output "Removing User Temporary Files ($env:TEMP)"
87+
Start-Sleep 1
88+
Get-ChildItem -Path $env:TEMP *.* -Recurse | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
89+
90+
Write-Output "
91+
If you see any errors stating ""Access is denied,"" don't worry, nothing is wrong.
92+
"
7793
}

0 commit comments

Comments
 (0)