troubleshooting Question

Script for exporting local admins in a csv

Avatar of Margarita
Margarita asked on
Active Directory
3 Comments2 Solutions69 ViewsLast Modified:
I need to export this to a CSV

Please help

function get-localadmins{
  $group = get-wmiobject win32_group -ComputerName $computerName -Filter "LocalAccount=True AND SID='S-1-5-32-544'"
  $query = "GroupComponent = `"Win32_Group.Domain='$($group.domain)'`,Name='$($'`""
  $list = Get-WmiObject win32_groupuser -ComputerName $computerName -Filter $query
  $list | ForEach{$_.PartComponent} | ForEach{$_.substring($_.lastindexof("Domain=") + 7).replace("`",Name=`"","\")}

foreach($computer in (Get-ADComputer -filter * | select name).name){
Write-Verbose "Checking $computer" -Verbose
get-localadmins -computerName $computer
Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
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 2 Answers and 3 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