Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions Ad Menu report script
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Import the Active Directory module
Import-Module ActiveDirectory

function Show-Menu {
Clear-Host
Write-Host "1: Count Users in AD"
Write-Host "2: Count Computer Objects in AD"
Write-Host "3: Count Groups in AD"
Write-Host "4: Accounts Created in Last X Days"
Write-Host "5: Computers Created in Last X Days"
Write-Host "6: Groups Created in Last X Days"
Write-Host "7: Inactive Accounts in Last 30 Days"
Write-Host "8: Inactive Accounts in Last X Days"
Write-Host "9: Computers Not Logged In in Last X Days"
Write-Host "10: Complete Report of Users, Computers, and Groups"
Write-Host "11: Deleted Objects in Last 5 Days"
Write-Host "0: Exit"
}

function Get-UserCount {
(Get-ADUser -Filter *).Count
}

function Get-ComputerCount {
(Get-ADComputer -Filter *).Count
}

function Get-GroupCount {
(Get-ADGroup -Filter *).Count
}

function Get-AccountsCreatedInLastXDays {
param (
[int]$days
)
$date = (Get-Date).AddDays(-$days)
Get-ADUser -Filter {whenCreated -ge $date} | Select-Object Name, whenCreated
}

function Get-ComputersCreatedInLastXDays {
param (
[int]$days
)
$date = (Get-Date).AddDays(-$days)
Get-ADComputer -Filter {whenCreated -ge $date} | Select-Object Name, whenCreated
}

function Get-GroupsCreatedInLastXDays {
param (
[int]$days
)
$date = (Get-Date).AddDays(-$days)
Get-ADGroup -Filter {whenCreated -ge $date} | Select-Object Name, whenCreated
}

function Get-InactiveAccountsLast30Days {
$date = (Get-Date).AddDays(-30)
Get-ADUser -Filter {lastLogonTimestamp -le $date} | Select-Object Name, lastLogonTimestamp
}

function Get-InactiveAccountsInLastXDays {
param (
[int]$days
)
$date = (Get-Date).AddDays(-$days)
Get-ADUser -Filter {lastLogonTimestamp -le $date} | Select-Object Name, lastLogonTimestamp
}

function Get-ComputersNotLoggedInInLastXDays {
param (
[int]$days
)
$date = (Get-Date).AddDays(-$days)
Get-ADComputer -Filter {lastLogonTimestamp -le $date} | Select-Object Name, lastLogonTimestamp
}

function Get-CompleteReport {
$userCount = Get-UserCount
$computerCount = Get-ComputerCount
$groupCount = Get-GroupCount
Write-Host "Users: $userCount"
Write-Host "Computers: $computerCount"
Write-Host "Groups: $groupCount"
}

function Get-DeletedObjectsLast5Days {
$date = (Get-Date).AddDays(-5)
Get-ADObject -Filter {isDeleted -eq $true -and whenChanged -ge $date} -IncludeDeletedObjects | Select-Object Name, whenChanged
}

do {
Show-Menu
$choice = Read-Host "Enter your choice"
switch ($choice) {
1 { Write-Host "User count in AD: $(Get-UserCount)" }
2 { Write-Host "Computer count in AD: $(Get-ComputerCount)" }
3 { Write-Host "Group count in AD: $(Get-GroupCount)" }
4 {
$days = Read-Host "Enter the number of days"
Get-AccountsCreatedInLastXDays -days $days | Format-Table -AutoSize
}
5 {
$days = Read-Host "Enter the number of days"
Get-ComputersCreatedInLastXDays -days $days | Format-Table -AutoSize
}
6 {
$days = Read-Host "Enter the number of days"
Get-GroupsCreatedInLastXDays -days $days | Format-Table -AutoSize
}
7 {
Write-Host "Inactive accounts in last 30 days:"
Get-InactiveAccountsLast30Days | Format-Table -AutoSize
}
8 {
$days = Read-Host "Enter the number of days"
Write-Host "Inactive accounts in last $days days:"
Get-InactiveAccountsInLastXDays -days $days | Format-Table -AutoSize
}
9 {
$days = Read-Host "Enter the number of days"
Write-Host "Computers not logged in last $days days:"
Get-ComputersNotLoggedInInLastXDays -days $days | Format-Table -AutoSize
}
10 { Get-CompleteReport }
11 {
Write-Host "Deleted objects in the last 5 days:"
Get-DeletedObjectsLast5Days | Format-Table -AutoSize
}
0 { Write-Host "Exiting..."; break }
default { Write-Host "Invalid choice, please select a valid option." }
}
Pause
} while ($choice -ne 0)

69 changes: 69 additions & 0 deletions DHCP_backup_complete_jetDB_and_textV2.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
 # === GLOBAL CONFIGURATION ===
$DateStamp = Get-Date -Format "yyyyMMdd_HHmmss"
$DateFolder = "DHCP Backup Dated $($DateStamp.Substring(0,8))"

# TEXT EXPORT DESTINATION
$TextRoot = "\\fs\backups\DHCP\DHCP_TextBackups"
$TextFolder = Join-Path -Path $TextRoot -ChildPath "DHCP_text_backup $DateStamp"
$TextLogFile = Join-Path -Path $TextRoot -ChildPath "dhcp_backup_status.log"

# JET DB DESTINATION
$JetRoot = "\\fs\backups\DHCP\DHCP_JetBackups"
$JetFolder = Join-Path -Path $JetRoot -ChildPath "DHCP Jet Backup $DateStamp"
$JetLogFile = Join-Path -Path $JetRoot -ChildPath "dhcp_jet_backup.log"
$JetSource = "$env:SystemRoot\System32\dhcp\backup"

# === GENERAL LOG FUNCTION ===
function Write-Log {
param (
[string]$Message,
[string]$LogPath
)
$Timestamped = "$(Get-Date -Format "s") - $Message"
Write-Output $Timestamped
try {
Add-Content -Path $LogPath -Value $Timestamped
} catch {
Write-Warning "Could not write to log file: $_"
}
}

# === TEXT EXPORT BACKUP ===
try {
New-Item -Path $TextFolder -ItemType Directory -Force | Out-Null
$ExportFile = Join-Path -Path $TextFolder -ChildPath "dhcp_backup_$DateStamp.txt"
netsh dhcp server export "$ExportFile" all
Write-Log "SUCCESS: DHCP text export saved to $ExportFile" $TextLogFile
} catch {
Write-Log "ERROR during text export: $($_.Exception.Message)" $TextLogFile
}

# === JET DB BACKUP ===
try {
Write-Log "Starting DHCP Jet database backup..." $JetLogFile

# Ensure destination exists
if (!(Test-Path $JetFolder)) {
New-Item -Path $JetFolder -ItemType Directory -Force | Out-Null
}

# Stop DHCP Server for clean backup
Write-Log "Stopping DHCP Server service..." $JetLogFile
Stop-Service dhcpserver -Force -ErrorAction Stop

# Copy the Jet database backup folder
Write-Log "Copying backup from $JetSource to $JetFolder..." $JetLogFile
Copy-Item -Path "$JetSource\*" -Destination $JetFolder -Recurse -Force -ErrorAction Stop

# Start DHCP Server again
Write-Log "Starting DHCP Server service..." $JetLogFile
Start-Service dhcpserver -ErrorAction Stop

Write-Log "SUCCESS: Jet database backup completed to $JetFolder" $JetLogFile
} catch {
Write-Log "ERROR: Jet DB backup failed - $($_.Exception.Message)" $JetLogFile
}

# === FINAL STATUS LOG ===
Write-Log "COMPLETED: DHCP backup finished for $DateStamp" $TextLogFile
Exit 0
49 changes: 49 additions & 0 deletions Sho shunned devices
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import paramiko
import getpass

def get_asa_shunned_devices(hostname, username, password):
try:
# Create an SSH client
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# Connect to the ASA
print(f"Connecting to {hostname}...")
client.connect(hostname, username=username, password=password)
print("Connected.")

# Open a shell session
ssh_shell = client.invoke_shell()

# Send the 'enable' command and provide the enable password if required
ssh_shell.send("enable\n")
ssh_shell.send(password + "\n")

# Send the 'show shun' command
ssh_shell.send("show shun\n")

# Allow some time for the command to execute and capture the output
ssh_shell.settimeout(2)
output = ""
while True:
try:
data = ssh_shell.recv(1024).decode('utf-8')
output += data
except paramiko.ssh_exception.SSHException:
break

# Print the output
print(output)

except Exception as e:
print(f"An error occurred: {e}")
finally:
client.close()

if __name__ == "__main__":
# Prompt for credentials
hostname = input("Enter the ASA hostname or IP address: ")
username = input("Enter your username: ")
password = getpass.getpass("Enter your password: ")

get_asa_shunned_devices(hostname, username, password)
Loading