0

I am using get-WmiObject -class Win32_Group to get a list of groups to interrogate. I am having the issue of no naming convention. There are group names like Admin Users , AdminUsers, Admin_Users, Admin WWW Users, Admin Users_, etc.

My issue is that when the group name is returned, the spaces are removed. So I'll end up with something like AdminUsers, AdminUsers, Admin_Users, AdminWWWUsers, AdminUsers_, etc.

As you can see some will work and some will end up broken. I handled some issues with Regex but ALL of the conditions are getting out of control (started simple, expanding as I started noticing there was no naming convention).

How can I return the list of group names as they exist, so I can look them up for interrogation.

I have had no luck finding a solution to this, but I'm sure it can be done!

gregnnylf94
  • 370
  • 3
  • 16
  • I suspect that this all stems from your statement '*I handled some issues with Regex*', and that you removed spaces to try and match similar names or some such. Without seeing more of your script I don't think we can help much. – TheMadTechnician Apr 20 '18 at 00:19

1 Answers1

1

On Windows 8/Server 2012 and above, you can utilize the following cmdlet:

Get-LocalGroup | Select-Object -Property 'Name'

Although, I was unable to replicate your issue with spaces stripped from WMI information.

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63
  • For what it is worth I cannot replicate missing spaces in names either. Corrupt WMI would be my first suspicion. – EBGreen Apr 19 '18 at 20:02
  • Really!? That's interesting, I'm going to re-examine my script now. Will post back. – gregnnylf94 Apr 19 '18 at 20:08
  • For before win 8/2012 you could try wrapping good old `net group` in an `invoke-command` for remoting and parse the output, albiet a hacky solution. – jkdba Apr 19 '18 at 23:29