Like that hipster beard you grew last summer, all good things must eventually come to an end. You will likely be aware that the end of extended support for Windows Server 2003 finishes on July 14th 2015. If you don’t know whether you still have 2003 boxes lurking in the dark recesses of your AD domain, you could try running the handy script below to flush them out.
The script looks for Window Server 2003 machine accounts that have logged on to the domain some time within the past 60 days – a good indicator that they are still active. It produces a CSV output for your perusal.
######################################################### # # Name: Find-W2K3StillActive.ps1 # Author: Tony Murray # Version: 1.0 # Date: 25/06/2015 # Comment: PowerShell 2.0 script to find active # Windows Server 2003 computer accounts # ######################################################### ## Define global variables # Export file for storing results $expfile = "c:\w2k3_still_active.csv" # Define the header row for the CSV (we will create our own) $header = "`"name`",`"os`",`"sp`",`"lastlogondate`"" # Consider any account logged on in the last x days to be active $days = 60 $Today = Get-date $SubtractDays = New-Object System.TimeSpan $days, 0, 0, 0, 0 $StartDate = $Today.Subtract($SubtractDays) $startdate = $startdate.ToFiletime() # LDAP filter settings $filter = "(&(lastlogontimestamp>=$startDate)(operatingsystem=Windows Server 2003*))" ## Functions Function Format-ShortDate ($fdate) { if ($fdate) { $day = $fdate.day $month = $fdate.month $year = $fdate.year "$day/$month/$year" } # end if } # end function ## Start doing things # Import the AD module ipmo ActiveDirectory # Tidy up any previous copies of the export file if (test-path $expfile) {Remove-Item $expfile} # Add the header row to the export file Add-Content -Value $header -Path $expfile # Create an array of computer objects $active = Get-ADComputer -LDAPFilter $filter -pr * # loop through the array foreach ($w2k3 in $active) { # Grab the attribute values we need from the AD object $nm = $w2k3.name $os = $w2k3.operatingsystem $sp = $w2k3.operatingsystemservicepack $lt = Format-ShortDate $($w2k3.lastlogondate) $row = "`"$nm`",`"$os`",`"$sp`",`"$lt`"" # Commit the row to the export file Add-Content -Value $row -Path $expfile } # end foreach ## End script
Enjoy!