List local user and user group membership using powershell

B14D3 61 Reputation points
2022-09-15T11:23:42.36+00:00

I am using this to extract local users but I need also to include the user group membership. I am not sure how insert that to this script.

$list = "c:\temp\ServerList.txt"
$report = "c:\temp\LocalUser.csv"
$computers = Get-Content -Path $list
Get-WmiObject -ComputerName $computers -Class Win32_UserAccount -Filter "LocalAccount=True" | Select PSComputername, Name | Export-CSV $report -NoTypeInformation -Append

Any idea?

TIA

Windows for business | Windows Server | User experience | PowerShell
Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2022-09-15T11:40:27.903+00:00

    Hi @B14D3 ,

    maybe this helps:

    https://github.com/abaumgarten42/Useful_PSscripts/blob/main/Get-LocalUsersAndLocalGroupMembership/Get-LocalUsersAndLocalGroupMembership.ps1

    Sorry I could not post the script directly here. Getting an error message every time.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  2. B14D3 61 Reputation points
    2022-09-19T23:01:16.493+00:00

    It work on local machine but how to check multiple remote machines with these output. TIA.

    242693-localuserscript.jpg

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.