@@ -12,6 +12,28 @@ Version 1.0: Init
1212Run as: System
1313Context: 64 Bit
1414#>
15+
16+ function Save-VerifiedDownload {
17+ param (
18+ [Parameter (Mandatory = $true )]
19+ [string ]$Uri ,
20+
21+ [Parameter (Mandatory = $true )]
22+ [string ]$OutFile ,
23+
24+ [Parameter (Mandatory = $true )]
25+ [string ]$ExpectedSha256
26+ )
27+
28+ Invoke-WebRequest - Uri $Uri - OutFile $OutFile - UseBasicParsing - ErrorAction Stop
29+ $actualHash = (Get-FileHash - Path $OutFile - Algorithm SHA256).Hash.ToLowerInvariant()
30+
31+ if ($actualHash -ne $ExpectedSha256.ToLowerInvariant ()) {
32+ Remove-Item - Path $OutFile - Force - ErrorAction SilentlyContinue
33+ throw " Hash validation failed for $OutFile . Expected $ExpectedSha256 , got $actualHash ."
34+ }
35+ }
36+
1537$days = 30
1638$profiles = (get-CimInstance win32_userprofile | Where-Object {$_.LastUseTime -lt $ (Get-Date ).Date.AddDays(- $days )})
1739$profilecount = $profiles.Count
@@ -22,18 +44,18 @@ $tempdir = $env:TEMP
2244# #Comment out whichever version you don't want to use
2345
2446# #Download DelProf1
25- Invoke-WebRequest - URI " https://github.com/andrew-s-taylor/public/raw/main/delprof/delprof.exe" - OutFile " $tempdir \delprof.exe"
47+ Save-VerifiedDownload - Uri " https://github.com/andrew-s-taylor/public/raw/main/delprof/delprof.exe" - OutFile " $tempdir \delprof.exe" - ExpectedSha256 " 1da35d3bc379f57de9384fef2ce8f9a29cea9f5e8a6550a5023f29f39bf327ad "
2648# #Run DelProf1
2749Start-Process - FilePath " $tempdir \delprof.exe" - ArgumentList / Q / D:$days
2850Remove-Item " $tempdir \delprof.exe"
2951
3052# #Download DelProf2
31- Invoke-WebRequest - URI " https://github.com/andrew-s-taylor/public/raw/main/delprof/DelProf2.exe" - OutFile " $tempdir \delprof2.exe"
53+ Save-VerifiedDownload - Uri " https://github.com/andrew-s-taylor/public/raw/main/delprof/DelProf2.exe" - OutFile " $tempdir \delprof2.exe" - ExpectedSha256 " b456e05c6825dea9f854e3ae37deb36e7f5f2d847fc2c7f053327559a9414ed6 "
3254# #Run DelProf2
3355Start-Process - FilePath " $tempdir \delprof2.exe" - ArgumentList / q / d:$days
3456remove-item " $tempdir \delprof2.exe"
3557
3658}
3759else {
3860write-host " No old profiles to remove" - ForegroundColor Green
39- }
61+ }
0 commit comments