Musings on the splendour of PowerShell
Extended support for Windows Server 2003 ends on July 14, 2015...
In Search of Lost Time
Hopefully, you've already migrated away from this operating system. If you haven't and you're looking to understand the scale of the task facing you, the following one-liner examples may prove useful.
This one will work with all versions of PowerShell and gives you a count of Windows Server 2003 operating systems from the Active Directory instance that you are logged on to:
System.DirectoryServices.DirectorySearcher is the TypeName of the .NET DirectorySearcher class. As the name suggests, we can use this to search Active Directory. The square brackets let us access the class and we pass an LDAP search string that filters on Windows 2003 Servers. The FindAll() method of the class is called with dot notation to retrieve objects from AD matching the LDAP filter. We then use more dot notation to display the information contained in the Count property, i.e. all Windows Server 2003 instances found.
The next example is exactly the same, except that we access System.DirectoryServices.DirectorySearcher by using the ADSISearcher Type Accelerator. Think of a Type Accelerator as a shortcut to an underlying TypeName. The following example will work with v2 of PowerShell and later.
Finally, let's use the Get-ADComputer cmdlet, introduced with v2 of PowerShell, to apply the same LDAP filter. This one looks less complicated.
(Get-ADComputer -LdapFilter "(&(&(sAMAccountType=805306369)(objectCategory=computer)(operatingSystem=Windows\20Server\202003*)))").Count
And, what about that LDAP filter? Basically, we're asking for ALL of the following conditions to be met:
Finally, take a look at my Get-ADServerCount function. This will produce a count of different operating system types for active (password changed within the last 90 days) servers.
:) Good Job. Thank you Ian.
Thank you Ian.