Move 150+ scripts from root and scripts/ into client/project directories: - clients/dataforth/scripts/ (110 files: AD2, sync, SSH, DB, DOS scripts) - clients/bg-builders/scripts/ (14 files: Lesley mgmt, Exchange, termination) - clients/internal-infrastructure/scripts/ (10 files: GDAP, Gitea, backups) - projects/msp-tools/scripts/ (9 files: CIPP, MSP onboarding, Datto) - projects/gururmm-agent/scripts/ (3 files: API test, JWT, record counts) - clients/glaztech/scripts/ (1 file: CentraStage removal) Also reorganized: - VPN scripts → infrastructure/vpn-configs/ - Retrieved API/JS files → api/ - Forum posts → projects/community-forum/forum-posts/ - SSH docs → clients/internal-infrastructure/docs/ - NWTOC/CTONW docs → projects/wrightstown-smarthome/docs/ - ACG website files → projects/internal/acg-website-2025/ - Dataforth docs → clients/dataforth/docs/ - schema-retrieved.sql → docs/database/ Deleted 24 tmp_*.ps1 one-off debug scripts (preserved in git history). Root reduced from 220+ files to 62 items (docs + directories only). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
102 lines
4.3 KiB
PowerShell
102 lines
4.3 KiB
PowerShell
# AD2 Automation Demo
|
|
# Demonstrates efficient WinRM operations vs individual SSH commands
|
|
|
|
Write-Host "=== AD2 Automation Demo ===" -ForegroundColor Cyan
|
|
Write-Host "Using WinRM for efficient remote operations`n"
|
|
|
|
# Setup credentials (read-only service account)
|
|
$password = ConvertTo-SecureString "vG!UCAD>=#gIk}1A3=:{+DV3" -AsPlainText -Force
|
|
$cred = New-Object System.Management.Automation.PSCredential("INTRANET\ClaudeTools-ReadOnly", $password)
|
|
|
|
# Example 1: Get AD User Summary
|
|
Write-Host "[1] Active Directory User Summary" -ForegroundColor Yellow
|
|
try {
|
|
$userStats = Invoke-Command -ComputerName 192.168.0.6 -Credential $cred -ScriptBlock {
|
|
$allUsers = Get-ADUser -Filter * -Properties Enabled, LastLogonDate
|
|
@{
|
|
Total = $allUsers.Count
|
|
Enabled = ($allUsers | Where-Object Enabled -eq $true).Count
|
|
Disabled = ($allUsers | Where-Object Enabled -eq $false).Count
|
|
RecentLogin = ($allUsers | Where-Object { $_.LastLogonDate -gt (Get-Date).AddDays(-30) }).Count
|
|
}
|
|
}
|
|
|
|
Write-Host " Total Users: $($userStats.Total)" -ForegroundColor Green
|
|
Write-Host " Enabled: $($userStats.Enabled)" -ForegroundColor Green
|
|
Write-Host " Disabled: $($userStats.Disabled)" -ForegroundColor Green
|
|
Write-Host " Active (30 days): $($userStats.RecentLogin)" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host " [ERROR] $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
|
|
# Example 2: Get Computer Inventory
|
|
Write-Host "`n[2] Active Directory Computer Inventory" -ForegroundColor Yellow
|
|
try {
|
|
$computerStats = Invoke-Command -ComputerName 192.168.0.6 -Credential $cred -ScriptBlock {
|
|
$allComputers = Get-ADComputer -Filter * -Properties OperatingSystem, LastLogonDate
|
|
@{
|
|
Total = $allComputers.Count
|
|
Windows = ($allComputers | Where-Object { $_.OperatingSystem -like "*Windows*" }).Count
|
|
Servers = ($allComputers | Where-Object { $_.OperatingSystem -like "*Server*" }).Count
|
|
Active = ($allComputers | Where-Object { $_.LastLogonDate -gt (Get-Date).AddDays(-30) }).Count
|
|
}
|
|
}
|
|
|
|
Write-Host " Total Computers: $($computerStats.Total)" -ForegroundColor Green
|
|
Write-Host " Windows Systems: $($computerStats.Windows)" -ForegroundColor Green
|
|
Write-Host " Servers: $($computerStats.Servers)" -ForegroundColor Green
|
|
Write-Host " Active (30 days): $($computerStats.Active)" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host " [ERROR] $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
|
|
# Example 3: Check Sync Status
|
|
Write-Host "`n[3] Dataforth Sync Status" -ForegroundColor Yellow
|
|
try {
|
|
$syncStatus = Invoke-Command -ComputerName 192.168.0.6 -Credential $cred -ScriptBlock {
|
|
$statusFile = "C:\Shares\test\_SYNC_STATUS.txt"
|
|
if (Test-Path $statusFile) {
|
|
Get-Content $statusFile -Tail 5
|
|
} else {
|
|
"Status file not found"
|
|
}
|
|
}
|
|
|
|
Write-Host " Last Sync Status:" -ForegroundColor Green
|
|
$syncStatus | ForEach-Object { Write-Host " $_" -ForegroundColor Gray }
|
|
} catch {
|
|
Write-Host " [ERROR] $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
|
|
# Example 4: List Recent Logs
|
|
Write-Host "`n[4] Recent Sync Logs" -ForegroundColor Yellow
|
|
try {
|
|
$logInfo = Invoke-Command -ComputerName 192.168.0.6 -Credential $cred -ScriptBlock {
|
|
$logFile = "C:\Shares\test\scripts\sync-from-nas.log"
|
|
if (Test-Path $logFile) {
|
|
$file = Get-Item $logFile
|
|
@{
|
|
Size = [math]::Round($file.Length / 1KB, 2)
|
|
LastModified = $file.LastWriteTime
|
|
LastLines = (Get-Content $logFile -Tail 3)
|
|
}
|
|
} else {
|
|
@{ Error = "Log file not found" }
|
|
}
|
|
}
|
|
|
|
if ($logInfo.Error) {
|
|
Write-Host " [WARNING] $($logInfo.Error)" -ForegroundColor Yellow
|
|
} else {
|
|
Write-Host " Log Size: $($logInfo.Size) KB" -ForegroundColor Green
|
|
Write-Host " Last Modified: $($logInfo.LastModified)" -ForegroundColor Green
|
|
Write-Host " Recent Activity:" -ForegroundColor Green
|
|
$logInfo.LastLines | ForEach-Object { Write-Host " $_" -ForegroundColor Gray }
|
|
}
|
|
} catch {
|
|
Write-Host " [ERROR] $($_.Exception.Message)" -ForegroundColor Red
|
|
}
|
|
|
|
Write-Host "`n=== Demo Complete ===" -ForegroundColor Cyan
|
|
Write-Host "All operations completed in a single WinRM session!" -ForegroundColor Green
|