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