Avatar of MRS
MRS
Flag for United States of America asked on

PowerShell insert brake after each returned object

Hi,
I have PowerShell script that returns members of local admin group on remote PC's, however I am trying to insert a brake for each group. Example:
Script:
function get-localadmin {
$computer = Get-Content C:\Computers\computers.txt
$admins = Gwmi win32_groupuser –computer $computer  
$admins = $admins |? {$_.groupcomponent –like '*"Administrators"'}
$admins | % {$_.partcomponent –match “.+Domain\=(.+)\,Name\=(.+)$” > $null
$matches[1].trim('"') + “\” + $matches[2].trim('"')
}
}
get-localadmin | Out-File C:\Computers\members.txt

Result:
PC6666\localadmin
PC6666\MRSUser
CORP\$Desktop Support
CORP\Domain Admins
PC7777\localadmin
PC7777\MRSUser
CORP\$Desktop Support
CORP\Domain Admins
PC9999\LocalAdmin
PC9999\MRSUser
CORP\$Desktop Support
CORP\Domain Admins
etc.

I need to insert a brake after each group so it returns in a better to read format. Example:

PC6666\localadmin
PC6666\MRSUser
CORP\$Desktop Support
CORP\Domain Admins

PC7777\localadmin
PC7777\MRSUser
CORP\$Desktop Support
CORP\Domain Admins

PC9999\LocalAdmin
PC9999\MRSUser
CORP\$Desktop Support
CORP\Domain Admins



Any suggestions are appreciated.
Powershell

Avatar of undefined
Last Comment
MRS

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
David Johnson, CD

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
MRS

ASKER
Thank you.....
MRS

ASKER
Can I ask one more thing regarding this?
How do I add to this on each line it's computer name?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23