CyberPolice

An epic windows securing and hardening script
Log | Files | Refs | README

UserList.ps1 (1751B)


      1 Write-Host Getting data on users... -ForegroundColor Gray
      2 $thispath=Split-Path -parent $MyInvocation.MyCommand.Definition
      3 $path = Split-Path -parent $thispath
      4 #Write-Host $path
      5 $path2=Get-content $path/CyberPoliceOutput/path.txt
      6 #Write-Host $path2
      7 $accounts = Get-Wmiobject Win32_UserAccount -filter 'LocalAccount=TRUE' | select-object -expandproperty Name
      8 
      9 if (!(Test-Path "$path2/users.txt"))
     10 {
     11    New-Item $path2/users.txt -ItemType file | Out-Null
     12    Write-Host "Created users.txt file!" -ForegroundColor Yellow
     13 }
     14 
     15 Write-host "Are you on an AD (Default is No)" -ForegroundColor Yellow 
     16 $Readhost = Read-Host "[Y/N]" 
     17 Switch ($ReadHost) { 
     18   Y {
     19    if (!(Test-Path "$path2/usersAD.txt"))
     20    {
     21       New-Item $path2/usersAD.txt -ItemType file | Out-Null
     22       Write-Host "Created usersAD.txt file!" -ForegroundColor Yellow
     23    }
     24    if (!(Test-Path "$path2/ADConnectedComputers.txt"))
     25    {
     26       New-Item $path2/ADConnectedComputers.txt -ItemType file | Out-Null
     27       Write-Host "Created ADConnectedComputers.txt file!" -ForegroundColor Yellow
     28    }
     29    Get-ADComputer -Filter * -Properties ipv4Address, OperatingSystem, OperatingSystemServicePack | Format-List name, ipv4*, oper* | Out-File -FilePath $path2/ADConnectedComputers.txt
     30    Write-Host "[AD] Connected Computers added to text file!" -ForegroundColor Yellow;
     31    Get-ADUser -Filter *  | Out-File -FilePath $path2/usersAD.txt
     32    Write-Host "[AD] Users added to text file!" -ForegroundColor Yellow;
     33   } 
     34   N { Write-Host "Ok." -ForegroundColor Gray } 
     35   Default { Write-Host "Ok." -ForegroundColor Gray } 
     36 } 
     37 
     38 Clear-content "$path2\users.txt"
     39 foreach($l in $accounts){
     40    Add-Content -Path $path2\users.txt -Value $l -PassThru
     41 }
     42 
     43 Write-Host "Users added to text file!" -ForegroundColor Yellow;