Last active
July 17, 2021 07:30
-
-
Save olejorgensen/c96da00fdcf4c9d2833dd681bcf5b867 to your computer and use it in GitHub Desktop.
Delete the Windows.old folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
The sample scripts are not supported under any Microsoft standard support | |
program or service. The sample scripts are provided AS IS without warranty | |
of any kind. Microsoft further disclaims all implied warranties including, | |
without limitation, any implied warranties of merchantability or of fitness for | |
a particular purpose. The entire risk arising out of the use or performance of | |
the sample scripts and documentation remains with you. In no event shall | |
Microsoft, its authors, or anyone else involved in the creation, production, or | |
delivery of the scripts be liable for any damages whatsoever (including, | |
without limitation, damages for loss of business profits, business interruption, | |
loss of business information, or other pecuniary loss) arising out of the use | |
of or inability to use the sample scripts or documentation, even if Microsoft | |
has been advised of the possibility of such damages. | |
#> | |
#Check if the script run with administrator privilege | |
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) | |
{ | |
$arguments = "& '" + $myinvocation.mycommand.definition + "'" | |
Start-Process powershell -Verb runAs -ArgumentList $arguments | |
Break | |
} | |
#Windows.old path | |
$path = $env:HOMEDRIVE+"\windows.old" | |
If(Test-Path -Path $path) | |
{ | |
#create registry value | |
$regpath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations" | |
New-ItemProperty -Path $regpath -Name "StateFlags1221" -PropertyType DWORD -Value 2 -Force | Out-Null | |
#start clean application | |
cleanmgr /SAGERUN:1221 | |
} | |
Else | |
{ | |
Write-Warning "There is no 'Windows.old' folder in system driver" | |
cmd /c pause | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment