Use movefile in sysinternals to clean files with powershell

the PFRO functionality deletes files the next boot, before some applications start to use the file.

Example (elevated):

Get-Item C:\DumpStack.log | %{ movefile '/nobanner' $_.FullName '""' }

$a = New-Object System.Collections.Generic.List[System.Object]
Get-ChildItem -Recurse ($env:USERPROFILE + '\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState')| %{$a += $_.FullName}
Get-ChildItem -Recurse ($env:USERPROFILE + '\AppData\Local\Microsoft\Windows\Explorer')| %{$a += $_.FullName}
Get-ChildItem -Recurse ($env:USERPROFILE + '\AppData\Local\Microsoft\Windows\Caches')| %{$a += $_.FullName}
Get-ChildItem -Recurse ($env:USERPROFILE + '\AppData\LocalLow\Microsoft\CryptnetUrlCache')| %{$a += $_.FullName}
Get-ChildItem -Recurse ($env:USERPROFILE + '\AppData\Local\Microsoft\Windows\WebCache')| %{$a += $_.FullName}

Get-ChildItem -Recurse C:\ProgramData\USOShared\Logs\System | %{$a += $_.FullName}
Get-ChildItem -Recurse C:\ProgramData\USOShared\Logs\User | %{$a += $_.FullName}
Get-ChildItem -Recurse C:\ProgramData\Microsoft\Windows\Caches | %{$a += $_.FullName}
Get-ChildItem -Recurse C:\Windows\ServiceProfiles\LocalService\AppData\Local\FontCache | %{$a += $_.FullName}

Check the filelist and final execute:

$a | %{echo $_}
$a | %{ movefile '/nobanner' $_ '""' }
1
所有评论 0