Posts mit dem Label Powershell werden angezeigt. Alle Posts anzeigen
Posts mit dem Label Powershell werden angezeigt. Alle Posts anzeigen
Mittwoch, 30. Dezember 2009
WSUS automated Cleanup
This script performs the cleanup tasks done by the WSUS cleanup wizard. Because it is a script, it can be automated (for example, via the Windows Task Scheduler). It also provides extended support for computer cleanup, allowing one to specify the number of days of not hearing from the computer before cleanup (default is 30 days), and to optionally skip deletion of computers that are still in Active Directory Directory Services (to avoid accidently removing computers that are still around but having trouble contacting the server). We recommend also performing SQL defragmentation sample script as part of WSUS cleanup.
Thx to ScriptingGuys.
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")`
| out-null
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
$cleanupScope = new-object Microsoft.UpdateServices.Administration.CleanupScope;
$cleanupScope.DeclineSupersededUpdates = $true
$cleanupScope.DeclineExpiredUpdates = $true
$cleanupScope.CleanupObsoleteUpdates = $true
$cleanupScope.CompressUpdates = $true
#$cleanupScope.CleanupObsoleteComputers = $true
$cleanupScope.CleanupUnneededContentFiles = $true
$cleanupManager = $wsus.GetCleanupManager();
$cleanupManager.PerformCleanup($cleanupScope);
Thx to ScriptingGuys.
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")`
| out-null
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
$cleanupScope = new-object Microsoft.UpdateServices.Administration.CleanupScope;
$cleanupScope.DeclineSupersededUpdates = $true
$cleanupScope.DeclineExpiredUpdates = $true
$cleanupScope.CleanupObsoleteUpdates = $true
$cleanupScope.CompressUpdates = $true
#$cleanupScope.CleanupObsoleteComputers = $true
$cleanupScope.CleanupUnneededContentFiles = $true
$cleanupManager = $wsus.GetCleanupManager();
$cleanupManager.PerformCleanup($cleanupScope);
Mittwoch, 16. Dezember 2009
Delete Files older then X Days Powershell
1. set-executionpolicy RemoteSigned
2. within a batch -> powershell -command "& 'SCRIPTNAME.ps1' " for Scheduled Task.
Function GetOldFile
{
$Days = "2"
$TargetFolder = "C:\pathtofolder"
if (Test-Path $TargetFolder)
{
$Now = Get-Date
$LastWrite = $Now.AddDays(-$days)
$Files = get-childitem $TargetFolder -include *.log -recurse |Where {$_.LastWriteTime -le "$LastWrite"}
foreach ($File in $Files)
{write-host "Deleting file $File" -foregroundcolor "Red"; Remove-Item $File | out-null}
}
Else
{Write-Host "Folder $TargetFolder doesnt exist! Recheck the folder path!"}
}
GetOldFile
2. within a batch -> powershell -command "& 'SCRIPTNAME.ps1' " for Scheduled Task.
Function GetOldFile
{
$Days = "2"
$TargetFolder = "C:\pathtofolder"
if (Test-Path $TargetFolder)
{
$Now = Get-Date
$LastWrite = $Now.AddDays(-$days)
$Files = get-childitem $TargetFolder -include *.log -recurse |Where {$_.LastWriteTime -le "$LastWrite"}
foreach ($File in $Files)
{write-host "Deleting file $File" -foregroundcolor "Red"; Remove-Item $File | out-null}
}
Else
{Write-Host "Folder $TargetFolder doesnt exist! Recheck the folder path!"}
}
GetOldFile
Abonnieren
Posts (Atom)