The other day I posted an article and function that used ADSI and PowerShell to list members of a local group. I had a few people report an unusual error that I couldn’t replicate. During the course of troubleshooting, I made a few changes to the original function to at least better handle the mysterious error. Those changes were updated to GitHub and as version 1.5 of the function.
But during testing and revising, I decided I might as well really improve this command and incorporate an option to use PowerShell remoting, without having to jump through all the hoops in the previous version.
Version 2 of the function includes a few parameters for remoting. This meant defining a few parameter sets. I also turned the bulk of the ADSI code into a scriptblock which can by invoked normally using the & operator. Or run remotely with Invoke-Command. One tricky thing with scriptblocks is being able to flip on Verbose output. My solution is to add a parameter to the scriptblock that essentially inherits the VerbosePreference of the local machine.
I also realized it might be helpful to include the group name in the results in case you want to export the information.
You can still use the command without remoting, which assumes you can create a legacy connection to the computer.
But I think you’ll find the remoting option better performing.
"chi-web02","chi-core01" | get-localgroupmember -UseRemoting |
format-table -GroupBy Computername -Property ADSPath,Name,Class
You can also use alternate credentials and SSL, although I haven’t tested using SSL or certificates since I don’t have that setup on my network.
Version 2 and later of the function can be found on Github:
Let me know if this works better for you.