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.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
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.
Ran the code on Windows 10 ( ps version 5, build 10586) got the following error:
WARNING: Oops. There was some other type of error: Error while invoking GetType. Could not find member.
Thank you. Yes, this does fail on Windows 10. I’ll have to dig into it. You can query a Windows 10 machine from Windows 8.1 but not ON a Windows 10 box.
I found the fix and update the versions on GitHub. The latest version with remoting is 2.1 so grab that and try again. Thanks for catching this.