troubleshooting Question

Exclude results from powershell CSV Exports.

Avatar of Can
Can asked on
Powershell
7 Comments4 Solutions68 ViewsLast Modified:
Hi All,

I got a script to export a list of local administrators on servers. I would like to exclude certain names and groups.  For example exclude names that starts with "L RG"
Any tips to apply this?

$servers= get-content 'C:\Localdata\5admin.csv'
$output = 'c:\localdata\alladmin.csv' 
$results = @()

foreach($server in $servers)
{
$admins = @()
$group =[ADSI]"WinNT://$server/Administrators" 
$members = @($group.psbase.Invoke("Members"))
$members | foreach {
 $obj = new-object psobject -Property @{
 Server = $Server
 Admin = $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
 }
 $admins += $obj
 } 
$results += $admins
}
$results| Export-csv $Output -NoTypeInformation

Thanks in advance.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 4 Answers and 7 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 4 Answers and 7 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