Skip to content

Instantly share code, notes, and snippets.

@suuhm
Last active April 12, 2024 14:28
Show Gist options
  • Save suuhm/2b0cb14598f43738d14611f857f0bb62 to your computer and use it in GitHub Desktop.
Save suuhm/2b0cb14598f43738d14611f857f0bb62 to your computer and use it in GitHub Desktop.
Get Windows Active Directory and Certificate Information (powershell / batch versions)
# Requires the Active Directory module
Import-Module ActiveDirectory
Write-Host "************************************"
Write-Host "* Get Active Directory Information *"
Write-Host "* (C) 204 By suuhmer *"
Write-Host "************************************"
Write-Host ""
# List users
Write-Host "Users:"
Get-ADUser -Filter * | Select-Object Name, SamAccountName, Enabled | Format-Table -AutoSize
# List groups
Write-Host "Groups:"
Get-ADGroup -Filter * | Select-Object Name, GroupScope, GroupCategory | Format-Table -AutoSize
# List computers
Write-Host "Computers:"
Get-ADComputer -Filter * | Select-Object Name, Enabled | Format-Table -AutoSize
# Check certificate connections (Example for AD CS connection)
Write-Host "Checking Certificate Connections:"
try {
# Attempt to connect to the Certificate Services
$certContext = New-Object System.Security.Cryptography.X509Certificates.X509Store("My","LocalMachine")
$certContext.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)
$certs = $certContext.Certificates
if ($certs.Count -gt 0) {
Write-Host "Successfully connected to Certificate Services. Number of certificates: $($certs.Count)"
} else {
Write-Host "No certificates found."
}
}
catch {
Write-Host "Failed to connect to Certificate Services: $_"
}
finally {
$certContext.Close()
}
@echo off
setlocal
echo ************************************
echo * Get Active Directory Information *
echo * (C) 204 By suuhmer *
echo ************************************
echo ------------------------------------
echo User List:
dsquery user -limit 10
echo ---------------------------------------
echo Group List:
dsquery group -limit 10
echo ---------------------------------------
echo Computer List:
dsquery computer -limit 10
echo ---------------------------------------
echo Checking Certificate Connections:
certutil -store My
echo ---------------------------------------
echo Script Execution Completed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment