Local User Account Report help

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

<li>Q1. Is anyone able to add my commands to an example for me to play with?</li>

<li>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?</li>

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 $outOutput

Hi Drew,

Whenever i am looking to grab information from several systems, i usually do it one of 2 ways, either i create a csv,txt file with the list of systems i want to check against, i then load that information into a variable and run it through a Foreach loop with the code you want in the middle.

The other way, is still using a foreach, but harcode the Computers into a variable, then run the loop against this. I find that CSV/Txt is easier for me personally.

Hope that gives you an idea,

$computername = "Computer1","Computer2"

$opt = New-CimSessionOption -Protocol Dcom
$session = New-CimSession -SessionOption $opt -ComputerName $ComputerName 
$profile = Get-CimInstance -CimSession $session -ClassName Win32_userprofile -ErrorAction SilentlyContinue

I like using CIM sessions when working with WMI. The computers can be a list like above or you can use a Get-ADGroupMember or any number of options to populate this variable. Using the protocol DCOM will allow you to connect to computers that do not have the most current PowerShell installed.

CIM Sessions are made concurrently so the collection of the profile data is quicker. If you run Get-CIMSession after the third line you will see a listing of the sessions. Plenty of information on the web on this - I think Don Jones has a few great videos on YouTube or the PowerShell videos on Microsoft Video Academy (free).

All of that data gets stored into the $profile variable. From there you can pull out what you need.

Hope this helps.

Good Luck!

@RShambo … thank you - this pointed me in the right direction. I have split my script into two:

Local User Report - SCRIPT #1

$computers = get-content "onlinecomputerreport_29_06.txt" $computers | foreach { $computername = $_ [ADSI]$S = "WinNT://$computername" $S.children.where({$_.class -eq 'group'}) | Select @{Name="Computername";Expression={$_.Parent.split("/")[-1] }}, @{Name="Name";Expression={$_.name.value}}, @{Name="Members";Expression={ [ADSI]$group = "$($_.Parent)/$($_.Name),group" $members = $Group.psbase.Invoke("Members") ($members | ForEach-Object { $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null) }) -join ";" }} } | Export-CSV -path "Report.csv" –notypeinformation

Get User Directories - SCRIPT #2

$computers = get-content “test.txt”
$localusers = foreach ($computer in $computers) {
Get-ChildItem “\$computer\C$\Users*” | Select-Object -Property @{Name=“Computers”; Expression = {$computer}}, FullName}
$localusers | ConvertTo-Html -Property Computers, FullName -CssUri “Style.css” | Out-File “Report.html”
#-ExpandProperty FullName broke script (removed)