From ae6414e8d85429163ce0f3f8b7cebead1fa2a45d Mon Sep 17 00:00:00 2001 From: Gabe Date: Tue, 5 Aug 2025 14:57:01 +0000 Subject: [PATCH] Upload files to "AD Scripts" --- AD Scripts/Get AD Computer's Local Users.ps1 | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 AD Scripts/Get AD Computer's Local Users.ps1 diff --git a/AD Scripts/Get AD Computer's Local Users.ps1 b/AD Scripts/Get AD Computer's Local Users.ps1 new file mode 100644 index 0000000..1ccd899 --- /dev/null +++ b/AD Scripts/Get AD Computer's Local Users.ps1 @@ -0,0 +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" +#Region Script End \ No newline at end of file