diff --git a/AD Scripts/Get AD Computer's Local Users.ps1 b/AD Scripts/AD - Get Computer's Local Users.ps1 similarity index 97% rename from AD Scripts/Get AD Computer's Local Users.ps1 rename to AD Scripts/AD - Get Computer's Local Users.ps1 index 1ccd899..914be1f 100644 --- a/AD Scripts/Get AD Computer's Local Users.ps1 +++ b/AD Scripts/AD - Get Computer's Local Users.ps1 @@ -1,43 +1,43 @@ -<# -Author: Gabe Kerntke -Date: 4/8/24 - -.Requirements -Needs to be run on a Domain Controller or where the "Active Directory module for Windows Powershell" Feature is installed. Also -Need to be running under credentials with Domain Admin rights. - -.Synopsis -Script will query all computers in the domain for local users. - -#> -#Import Module -Import-module ActiveDirectory - -#Set default error action -$ErrorActionPreference = "SilentlyContinue" - -#Variables for paths -$OutputDirectory = "C:\Temp\Script Cache" -$CSVOutput = "$OutputDirectory\Local_Users.csv" - -#Variable to find all AD computers -$Computers = Get-ADComputer -filter * | Select-Object -ExpandProperty Name - -#Region Script Start - -#Create output directory if it doesn't exist -If ((Test-Path $OutputDirectory) -eq $False) { New-Item -ItemType directory -Path $OutputDirectory } - -#Remove existing CSV output file to prevent issues -If ((Test-Path $CSVOutput -ErrorAction SilentlyContinue) -eq $True) { Remove-Item $CSVOutput -Force } - -foreach ($Computer in $Computers) { - $Computer | Foreach-Object { - If ((Test-Connection $Computer -Quiet) -eq $true) { - Get-WmiObject -ComputerName $Computer -Class Win32_UserAccount -Filter "LocalAccount=True" | Select-Object PSComputerName, Name, Disabled - } - - } | Export-Csv -Path $CSVOutput -Append -NoType -} -Write-host "Script Output: $CSVOutput" +<# +Author: Gabe Kerntke +Date: 4/8/24 + +.Requirements +Needs to be run on a Domain Controller or where the "Active Directory module for Windows Powershell" Feature is installed. Also +Need to be running under credentials with Domain Admin rights. + +.Synopsis +Script will query all computers in the domain for local users. + +#> +#Import Module +Import-module ActiveDirectory + +#Set default error action +$ErrorActionPreference = "SilentlyContinue" + +#Variables for paths +$OutputDirectory = "C:\Temp\Script Cache" +$CSVOutput = "$OutputDirectory\Local_Users.csv" + +#Variable to find all AD computers +$Computers = Get-ADComputer -filter * | Select-Object -ExpandProperty Name + +#Region Script Start + +#Create output directory if it doesn't exist +If ((Test-Path $OutputDirectory) -eq $False) { New-Item -ItemType directory -Path $OutputDirectory } + +#Remove existing CSV output file to prevent issues +If ((Test-Path $CSVOutput -ErrorAction SilentlyContinue) -eq $True) { Remove-Item $CSVOutput -Force } + +foreach ($Computer in $Computers) { + $Computer | Foreach-Object { + If ((Test-Connection $Computer -Quiet) -eq $true) { + Get-WmiObject -ComputerName $Computer -Class Win32_UserAccount -Filter "LocalAccount=True" | Select-Object PSComputerName, Name, Disabled + } + + } | Export-Csv -Path $CSVOutput -Append -NoType +} +Write-host "Script Output: $CSVOutput" #Region Script End \ No newline at end of file