remove oldest shadow copy
This commit is contained in:
@@ -109,15 +109,18 @@ If ( Test-Path $ESDB ) {
|
|||||||
$ADSKInst = "${Env:SystemDrive}\Autodesk"
|
$ADSKInst = "${Env:SystemDrive}\Autodesk"
|
||||||
If ( Test-Path $ADSKInst ) {
|
If ( Test-Path $ADSKInst ) {
|
||||||
$foldersToDelete = Get-ChildItem -Path $ADKSInst -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer) -and ($_.LastWriteTime -lt ((Get-Date) - $TimeDelta)) -and ( $_.Name -ne "WI") }
|
$foldersToDelete = Get-ChildItem -Path $ADKSInst -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer) -and ($_.LastWriteTime -lt ((Get-Date) - $TimeDelta)) -and ( $_.Name -ne "WI") }
|
||||||
ForEach ( $folder in $foldersToDelete ) {
|
ForEach ( $f in $foldersToDelete ) {
|
||||||
$path = $folder.FullName
|
$path = $f.FullName
|
||||||
Write-Output "Deleting Autodesk installer directory: ""${path}"""
|
Write-Output "Deleting Autodesk installer directory: ""${path}"""
|
||||||
Try { Remove-Item $folder -Force -Recurse -ErrorAction SilentlyContinue }
|
Try { Remove-Item $f -Force -Recurse -ErrorAction SilentlyContinue }
|
||||||
Catch { Write-Error $_.Exception.Message }
|
Catch { Write-Error $_.Exception.Message }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO: Evaluate system restore points and delete them if they take up too much space
|
# Delete the oldest shadow copies if there are more than 1
|
||||||
|
$SystemVolume = Get-CimInstance -ClassName Win32_Volume -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "${Env:SystemDrive}\" }
|
||||||
|
$ShadowCopies = Get-CimInstance -ClassName Win32_ShadowCopy | Where-Object { $_.VolumeName -like $SystemVolume.DeviceID }
|
||||||
|
If ( $ShadowCopies.Length -gt 1 ) { vssadmin delete shadows /For=$Env:SystemDrive /Oldest /Quiet }
|
||||||
|
|
||||||
# Remove files from user profile directories
|
# Remove files from user profile directories
|
||||||
ForEach ( $userProfile in $(Get-UserProfiles) ) {
|
ForEach ( $userProfile in $(Get-UserProfiles) ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user