[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 742
  • Last Modified:

List local user account from a CSV file

Can any experts can help me plsssss

I have the attached CSV format computer list, is it possible to list out the local user account from the list and output the user account list to another CSV file?

Thanks
Book1.csv
0
gcl_hk
Asked:
gcl_hk
1 Solution
 
Chris DentPowerShell DeveloperCommented:
Hello there,

You can do it like this:
Get-Content book1.csv | ForEach-Object {

  $Computer = $_

  ([ADSI]"WinNT://$Computer").PsBase.Children | 
    Where-Object { $_.Class -eq "User" } |
    Select-Object `
      @{n='ComputerName';e={ $Computer }},
      @{n='Name';e={ $_.Name[0] }}, 
      @{n='Disabled';e={ If ($_.UserFlags[0] -BAnd 2) { $True } else { $False } }}

} | Export-Csv Output.csv -NoTypeInformation

Open in new window

This snippet exports the account name and whether or not the account is disabled.

HTH

Chris
0
 
gcl_hkAuthor Commented:
thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now