blog: Breaking down DCDiag.exe to an object
Using some regex magic and some custom object mojo I threw together this DCDiag objectifier.
These are very early bits (only spent a few minutes on it) and may not go any further as I think this would be better as a cmdlet, but it was fun to play with and show some of the POWER you have at your finger tips.
The Code
# Creating the DCDiag object
$DCDiagObject = "" | Select-Object Server,Advertising,SPNs,KnownRoles,Tests
$DCDiagObject.Server = ""
$DCDiagObject.Advertising = @()
$DCDiagObject.KnownRoles = @()
$DCDiagObject.SPNs = @()
$DCDiagObject.Tests = @()
# Setting up RegEXs here so they are easier to consume for the viewer
$DCNameRegex = "^s** Connecting to directory service on server (?<DCName>w+)."
$Advertising = "^s+ThesDCsw*sissadvertisingsass(a|an|having a)s(?<Type>.*)"
$KnownRolesRegex = "^.*Roles(?<Role>.*)sOwner = CN=NTDS Settings,CN=(?<Holder>w*),"
$SPNsRegex = "^s+* SPN found :(?<SPN>.*)"
$StartRegex = "^s*.+s(?<Target>w+)s(?<Result>w+)stests(?<Test>w+)"
# Getting stuff done
switch -regex ($DCDiag)
{
$DCNameRegex {$DCDiagObject.Server = $matches.DCName}
$Advertising {$DCDiagObject.Advertising += $matches.Type}
$KnownRolesRegex {$DCDiagObject.KnownRoles += $matches.Role}
$SPNsRegex {$DCDiagObject.SPNs += $matches.SPN}
$StartRegex {
$myobj = "" | Select-Object Target,Test,Result
$myobj.Target = $matches.Target
$myobj.Test = $matches.Test
$myobj.Result = $matches.Result
$myobj | Add-Member -MemberType ScriptMethod -name ToString -value {$this.Test} -force
$DCDiagObject.Tests += $myobj
}
}
# outputting object
$DCDiagObject
tshell :: May.03.2009 :: Active Directory, All :: No Comments »

