We help IT Professionals succeed at work.

PowerShell insert brake after each returned object

MRS
MRS asked
on
230 Views
Last Modified: 2017-03-21
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.
Comment
Watch Question

Simple Geek from the '70s
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
MRS

Author

Commented:
Thank you.....
MRS

Author

Commented:
Can I ask one more thing regarding this?
How do I add to this on each line it's computer name?

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions