Category Archives: IT Security

Patch Tuesdays 2012

I’ve shown these functions before but as we head rapidly towards 2012 we need to plan next years schedules.  One perennial for Windows administrators is patching – therefore we need to know patch Tuesdays. This is next years offenders 10 … Continue reading

Posted in IT Security, Powershell | Leave a comment

Set registry key owner

In chapter 7 of PowerShell and WMI I stated that I would post a .NET version of a script to set ownership of a registry key. The WMI method needs Vista or above so we need the .NET version for … Continue reading

Posted in .NET, IT Security, PowerShell V2 | Leave a comment

Using AccountManagement classes to set local accounts expiry

This is a little more verbose than the WinNT example function set-expirydate { [CmdletBinding(SupportsShouldProcess=$true)] param ( [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string]$computer, [parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string]$id ) BEGIN {Add-Type -AssemblyName System.DirectoryServices.AccountManagement} PROCESS { switch ($computer){ “.” {$computer = $env:computername} “localhost” {$computer = $env:computername} } … Continue reading

Posted in IT Security, PowerShell and Active Directory, Windows 7, Windows Server 2008, Windows Server 2008 R2 | Leave a comment

Setting local account expiry dates

Setting expiry dates on AD accounts is a common occurrence and is well documented. Setting expiry dates on local accounts is also possible $user = [adsi]”WinNT://./Test1, user” $expirydate = (Get-Date).AddDays(2) $user.Put(“AccountExpirationDate”, $expirydate) $user.SetInfo() $user.RefreshCache() $user | Format-List * This uses … Continue reading

Posted in IT Security, PowerShell and Active Directory, Windows 7, Windows Server 2008, Windows Server 2008 R2 | Leave a comment

Windows Update: 5 drivers

The previous posts just looked at installing software updates.  We can also get driver updates through Windows updates. A simple modification to the get-updates function sets this up. function get-drivers {[CmdletBinding()] param ( [switch]$hidden ) PROCESS{ $session = New-Object -ComObject … Continue reading

Posted in IT Security, PowerShell V2, Technology | Leave a comment

Windows updates: 4 tidy up get-update

Looking at the get-update function we created earlier I wanted to tidy it up a bit. 001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033 function get-update {[CmdletBinding()] param (  [switch]$hidden ) PROCESS{ $session = New-Object -ComObject Microsoft.Update.Session$searcher = $session.CreateUpdateSearcher() # 0 = false & 1 = trueif ($hidden){ $result = $searcher.Search(“IsInstalled=0 and Type=’Software’ and ISHidden=1” )}else { $result = $searcher.Search(“IsInstalled=0 and Type=’Software’ and ISHidden=0” )} if ($result.Updates.Count -gt 0){ $result.Updates |  select Title, IsHidden, IsDownloaded, IsMandatory,  IsUninstallable, RebootRequired, Description}else { Write-Host ” No updates available”}  }#process … Continue reading

Posted in COM, IT Security, PowerShell V2 | 5 Comments

Windows Updates: 3 Installing Updates

Now we have discovered the updates we have available we can think about installing them. 001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037 function install-update { $session = New-Object -ComObject Microsoft.Update.Session$searcher = $session.CreateUpdateSearcher() $result = $searcher.Search(“IsInstalled=0 and Type=’Software’ and ISHidden=0” ) if ($result.Updates.Count -eq 0) { Write-Host “No updates to install”}else {$result.Updates | select Title} $downloads = New-Object -ComObject Microsoft.Update.UpdateColl foreach ($update in $result.Updates){ $downloads.Add($update)} $downloader = $session.CreateUpdateDownLoader()$downloader.Updates = $downloads$downloader.Download() $installs = New-Object -ComObject Microsoft.Update.UpdateCollforeach ($update in $result.Updates){ if ($update.IsDownloaded){   $installs.Add($update) }} $installer = $session.CreateUpdateInstaller()$installer.Updates = $installs$installresult = $installer.Install()$installresult }   The function looks for non-hidden software … Continue reading

Posted in COM, IT Security, PowerShell V2 | 1 Comment