Имеется скрипт на сайте: http://www.bryanvine.com/2015/06/powershell-script-cleaning-up.html. Как его переделать полностью на PS?
$msi = New-Object -ComObject WindowsInstaller.Installer
$savelist = @()
$products = $msi.GetType().InvokeMember("Products","GetProperty",$null,$msi,$null)
foreach($product in $products)
{
$patches = $msi.GetType().InvokeMember("Patches","GetProperty",$null,$msi,@($product))
foreach($patch in $patches)
{
$location = $msi.GetType().InvokeMember("PatchInfo","GetProperty",$null,$msi,@($patch,"LocalPackage"))
$savelist += [pscustomobject]@{
ProductCode = $product
PatchCode = $patch
PatchLocation = $location
}
}
}
$filelocation = $savelist | select -ExpandProperty PatchLocation
#First pass to remove exact file names
dir C:\windows\Installer -file | ForEach-Object{
$fullname = $_.FullName
if($filelocation | Where-Object{$_ -like "*$fullname*"}){
"Keeping $fullname"
}
else{
Remove-Item $fullname -Force -Verbose
}
}
#second pass to match product and patch codes
dir C:\windows\Installer -Directory | ForEach-Object{
$fullname = $_.name
if($savelist | Where-Object{$_.ProductCode -like "*$fullname*" -or $_.PatchCode -like "*$fullname*" }){
"Keeping $fullname"
}
else{
Remove-Item $_.fullname -Force -Verbose -Recurse
}
}
Спасибо большое, но такой вопрос назрел: на виртуалке после очередного запуска его скрипта, папка очистилась совсем. В чем может быть дело?
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.