Solved

Powershell - Local accounts information .

Posted on 2013-11-25
3
598 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 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

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

This article explains how to install and use the NTBackup utility that comes with Windows Server.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
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 setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

729 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