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 Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,913 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,504 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Andreas Baumgarten 107.9K Reputation points MVP
    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.