S.DS.AD – netlogon service 2

Last time I said that I wanted to improve the way the data was displayed when we interrogated the netlogon service on our domain controllers. One way we could do it is to use Add-Member to add the data to an object

$a = @()
$type = [System.DirectoryServices.ActiveDirectory.DirectoryContextType]::Domain
$context = New-Object -TypeName System.DirectoryServices.ActiveDirectory.DirectoryContext -ArgumentList $type, "manticore.org"
$dcs = [System.DirectoryServices.ActiveDirectory.DomainController]::FindAll($context)
foreach ($dc in $dcs){
    $s = Get-Service -ComputerName $dc.Name -Name netlogon
    $o = New-Object -TypeName psobject
    $o | Add-Member -MemberType Noteproperty  -Name Name -Value $dc.Name -Force
    $o | Add-Member -MemberType NoteProperty  -Name Status -Value $s.Status -Force
    $a += $o
}
$a | Format-Table -AutoSize

Start by creating an empty array.  We then get our domain controllers as before and iterate through them.  We then create a new object – in this case its a PowerShell object – and use Add-Member to add the properties of the object.  The object is then added to the array.

This technique could be extended to add any number of properties including the current time on the DC that we looked at previously or the status of other services or the replication status.

Format-table is used to display the data. 

A useful technique for pulling data together from multiple objects.

 

Technorati Tags: ,

About these ads
This entry was posted in PowerShell and Active Directory. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s