gregnnylf94
gregnnylf94

Reputation: 380

Powershell Group Names Returning With No Spaces

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!

Upvotes: 0

Views: 300

Answers (1)

Maximilian Burszley
Maximilian Burszley

Reputation: 19634

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.

Upvotes: 1

Related Questions