Solved

Powershell - Local accounts information .

Posted on 2013-11-25
3
587 Views
Last Modified: 2013-11-26
Subsun helped me out on the script below and I was wondering if anyone can help or if possible for the script to show if the account is Enabled/Disabled and the Full Name and Description on the local account .

function get-localusers {
    param(
    [Parameter(Mandatory=$true,valuefrompipeline=$true)]
    [string]$strComputer)
    begin {}
    Process {
      $Select = "Name","Class" | %{  
      Invoke-Expression "@{n='$_';e={ `$_.GetType().InvokeMember('$_', 'GetProperty', `$Null, `$_, `$Null) }}"  
       }
        If (Test-Connection $strComputer -Count 2 -Quiet){
         $computer = [ADSI]("WinNT://" + $strComputer + ",computer")
         $Users = $computer.psbase.children | ? {$_.psbase.SchemaClassName -eq "User"}
       foreach ($User in $Users) {
        $User | Select @{N="ComputerName";E={$strComputer}},@{N="User";E={$_.Name}},Class
       }
        }
      Else {
          "" | Select @{N="ComputerName";E={$strComputer}},@{N="User";E={"Not able to Ping"}},Class
        }
      }
end {}
}
Get-Content "e:\Projects\servers\Servers.txt" | get-localusers | Select ComputerName,User | Export-Csv "e:\Projects\Servers\LocalTest_$((get-date).toString('MM-dd-yyyy')).csv" -NTI
0
Comment
Question by:MilesLogan
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39676769
Try..
function get-localusers {
    param(
    [Parameter(Mandatory=$true,valuefrompipeline=$true)]
    [string]$strComputer)
    begin {}
    Process {
      $Select = "Name","Class" | %{  
      Invoke-Expression "@{n='$_';e={ `$_.GetType().InvokeMember('$_', 'GetProperty', `$Null, `$_, `$Null) }}"  
       }
       If (Test-Connection $strComputer -Count 2 -Quiet){
       $computer = [ADSI]("WinNT://" + $strComputer + ",computer")
       $Users = $computer.psbase.children | ? {$_.psbase.SchemaClassName -eq "User"}
       foreach ($User in $Users) {
	   $stat = Switch ($User.UserFlags.Value -band "2"){"2"{"Disabled"};"0"{"Enabled"}}
	   $User | Select @{N="ComputerName";E={$strComputer}},@{N="User";E={$_.Name}},@{N="Status";E={$stat}},@{N="Description";E={$_.Description}},Class
          }
        }
      Else {
          "" | Select @{N="ComputerName";E={$strComputer}},@{N="User";E={"Not able to Ping"}},Status,Description,Class
        }
      }
end {}
}
Get-Content "e:\Projects\servers\Servers.txt" | get-localusers | Select ComputerName,User,Status,Description,Class | Export-Csv "e:\Projects\Servers\LocalTest_$((get-date).toString('MM-dd-yyyy')).csv" -NTI

Open in new window

0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 39677862
MVP !! wow .. thanks Subsun !
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39679083
You are welcome!.. :-)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now