Powershell

Quick and dirty one here…

73# $dcObj = [adsi]"LDAP://OU=domain controllers,dc=domain,dc=local"
74# $dcs = $dcObj.PSBase.Children | % { $_.name }
75# $dcs
ATLDOMSRVP05
ATLDOMSRVP06
ATLDOMSRVP07
ATLDOMSRVP08
BRUDOMSRVP02
KASDOMSRVP02
SOUDOMSRVP01
TOKDOMSRVP01

Of course now that you have a list like this, you can pipe it to another cmdlet to do useful things!

$dcs | % { Get-WmiObject win32_service -Filter "startmode = 'disabled'" -computer $_ }

And as some will know, “%” is shorthand for the “Foreach-Object” cmdlet.

: http://halr9000.com/article/433

trenton
2007-09-14 06:40:21

…And tomorrow I will give you another assignment. :)

2007-09-14 10:18:56

Thanks!

2007-09-14 11:06:14

Here is different way
$context = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext(“Domain”,”fully.qualified.domain.name”)
$dclist = [System.DirectoryServices.ActiveDirectory.DomainController]::findall($context)
$dclist | %{$_.name}

this will not only give you name, but all kinds of DC goodness

(note that “Domain” on line 1 is a literal string)

  • Microblog

  • Recent Posts

  • Recent Comments

  • meta

  • PowerShell Blogroll