Local User Report | ForEach-Loop & Remote questions

Welcome Forums General PowerShell Q&A Local User Report | ForEach-Loop & Remote questions

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 10 months ago.

  • Author
  • #73664

    Topics: 6
    Replies: 5
    Points: 0
    Rank: Member

    Hi All,

    Working on a script to report the local user account information from a system and display them in a HTML report or CSV.

    I'm studying For-Each loops and want to loop through my Various Commands and append them to a table.

    Command 1) Hostname

    Command 2) (net localgroup administrators).where({$_ -match '-{79}'},'skipuntil') -notmatch '-{79}|The command completed'

    Command 3) Get-WmiObject -Class Win32_UserAccount -Filter "LocalAccount='True'" | Select name -expandproperty name

    Command 4) Get-ChildItem -Path C:\Users\ | select-object Name

  • Q1. Is anyone able to add my commands to an example for me to play with?
  • Q2. I have to run this against computers (200+) within a domain. There are only a few systems with WSMan enabled, I will need to look at that on a separate note. If WS Man was enabled across all systems, would invoke-command would be the best option?
  • As my script stands, I can Enter-PSSession and manually RUN the script against a remote PC, but I want to do this against ALL my computers.

    $A = hostname

    $B = (net localgroup administrators).where({$_ -match '-{79}'},'skipuntil') -notmatch '-{79}|The command completed'

    $C = Get-WmiObject -Class Win32_UserAccount -Filter "LocalAccount='True'" | Select name -expandproperty name

    $D = Get-ChildItem -Path C:\Users\ | select-object Name

    $out = new-object psobject
    $out | add-member noteproperty Node $a
    $out | add-member noteproperty Administrators $b
    $out | add-member noteproperty LocalAccounts $c
    $out | add-member noteproperty Profiles $d
    write-output $out


  • #73690

    Topics: 1
    Replies: 1325
    Points: 1,651
    Helping Hand
    Rank: Community Hero

    Really often you are not the first with a given task. Did you try to search for a solution? If I search in Google for "powershell wmi local administrators group" I get as the first hit "Get remote machine members of Local Administrator group"
    So no need to reinvent the wheel. 😉

    ... and also really often looking at other peoples code is indeed a great way to learn somthing about Powershell.

  • The topic ‘Local User Report | ForEach-Loop & Remote questions’ is closed to new replies.

    denizli escort samsun escort muğla escort ataşehir escort kuşadası escort