PowerShell insert brake after each returned object

MRS
MRS used Ask the Experts™
on
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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
function get-localadmin {
  $admins = Get-WmiObject win32_groupuser -computer $computer  
  $admins = $admins |Where-Object {$_.groupcomponent -like '*"Administrators"'}
  $admins | ForEach-Object {$_.partcomponent -match ".+Domain\=(.+)\,Name\=(.+)$" > $null
  $matches[1].trim('"') + "\" + $matches[2].trim('"')
  }
}
Remove-Item -Path c:\computers\members.txt -ErrorAction SilentlyContinue
$computers = Get-Content C:\Computers\computers.txt
foreach($computer in $computers)
  {
  get-localadmin | Out-File C:\Computers\members.txt -append
#two single quotes not a double quote
  '' | Out-File C:\Computers\members.txt -append
  }

Open in new window

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?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial