Here is the completed script, so far:
$a = edit-Object -comobject Excel.Application
$a.visible = $True
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)
# If you remove the pound symbol for $ADSPath, be sure to place pound signs in front of Domain and Members. They provide the same information
$c.Cells.Item(1,1) = "Server Name"
#$c.Cells.Item(1,2) = "ADSPath"
$c.Cells.Item(1,2) = "Domain"
$c.Cells.Item(1,3) = "Members"
$c.Cells.Item(1,4) = "Date Run"
$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True
$intRow = 2
# Change \\disk24\... to your server list file path.
foreach ($strComputer in get-content \\disk24\...\...\Servers.Txt)
{
[ADSI]$Admins="WinNT://$strcomputer/Administrators,group"
$Admins.psbase.invoke("Members") | ForEach-Object {
$name=$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
$ADSPath=$_.GetType().InvokeMember("ADSPath", 'GetProperty', `
$null, $_, $null)
$domain=$ADSPath.Split("/")[2]
#if computer name is found between two /, then assume
#the ADSPath reflects a local object
if ($ADSPath -match "/$env:computername/") {
$local=$True
}
else {
$local=$False
}
if ($name -match "55544") {$domain="LOCAL"
$c.Cells.Item($intRow,3).Interior.ColorIndex = 4}
write $name
# If you remove the pound symbol for $ADSPath, be sure to place pound signs in front of $domain and $name. They provide the same information.
$c.Cells.Item($intRow,1) = $strComputer.ToUpper()
#$c.Cells.Item($intRow,2) = $ADSPath
$c.Cells.Item($intRow,2) = $domain
$c.Cells.Item($intRow,3) = $name
$c.Cells.Item($intRow,4) = Get-Date
$intRow = $intRow + 1
}
$d.EntireColumn.AutoFit()
}