?
Solved

Powershell - Local accounts information .

Posted on 2013-11-25
3
Medium Priority
?
599 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 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

Ransomware Attacks Keeping You Up at Night?

Will your organization be ransomware's next victim?  The good news is that these attacks are predicable and therefore preventable. Learn more about how you can  stop a ransomware attacks before encryption takes place with our Ransomware Prevention Kit!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
Suggested Courses

800 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