troubleshooting Question

Formating of HTML output

Avatar of daveTechSearch
daveTechSearchFlag for Canada asked on
Shell ScriptingPowershell
4 Comments1 Solution540 ViewsLast Modified:
Objective: Query local adminstrators group for group membership on remote systems

Getting what I want so far, one step at a time, but need to get the results for 'Members' each on their own line.  Right now it is just getting strung to gether.

My goal is to keep the output in HTML format, eventually need to figure out how to add an additional column to:
1. Query each group member and determine if it is a local user, domain user, or domain group.
2. If the member is a domain group, expand the group.

My main focus right now is to properly format the 'members', one per line.

This will be supplied to our security team once it is complete....
$serverList = (read-host "Enter servers to query (separate with comma)").split(',') | %{$_.trim()}
$cellFormat = "<style>"
$cellFormat = $cellFormat + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$cellFormat = $cellFormat + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$cellFormat = $cellFormat + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$cellFormat = $cellFormat + "</style>"
$outputFile = read-host "Please enter path/name for output file (include .htm extention)"

@(foreach($server in $serverList)

$group = [ADSI]("WinNT://$server/Administrators,group")   
$GMembers = $group.psbase.invoke("Members") 
$obj = new-object PSObject

$obj | add-member NoteProperty -Name "ServerName" -Value $server
$obj | add-member NoteProperty -Name "Members" -Value ($GMembers | ForEach-Object {($_.GetType().InvokeMember("Name",'GetProperty', $null, $_, $null)).split(',')}| out-string)


}) | convertTo-HTML -head $cellFormat | set-content $outputFile

invoke-item $outputFile
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros