Initial commit: Organized PowerShell scripts for ShopDB asset collection
Structure: - asset-collection/: Local PC data collection scripts - remote-execution/: WinRM remote execution scripts - setup-utilities/: Configuration and testing utilities - registry-backup/: GE registry backup scripts - winrm-https/: WinRM HTTPS certificate setup - docs/: Complete documentation Each folder includes a README with detailed documentation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
170
setup-utilities/Test-API-Connection.ps1
Normal file
170
setup-utilities/Test-API-Connection.ps1
Normal file
@@ -0,0 +1,170 @@
|
||||
# Test script for ShopDB API connectivity and functionality
|
||||
# Tests the new Phase 2 ASP API endpoint
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$DashboardURL = "http://192.168.122.151:8080/api.asp"
|
||||
)
|
||||
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host "ShopDB API Connection Test" -ForegroundColor Cyan
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Test 1: Basic connectivity
|
||||
Write-Host "Test 1: Basic API Connectivity" -ForegroundColor Yellow
|
||||
try {
|
||||
$response = Invoke-RestMethod -Uri "$DashboardURL?action=getDashboardData" -Method Get -TimeoutSec 10
|
||||
if ($response.success) {
|
||||
Write-Host " [OK] API is online" -ForegroundColor Green
|
||||
Write-Host " Message: $($response.message)" -ForegroundColor Gray
|
||||
Write-Host " Version: $($response.version)" -ForegroundColor Gray
|
||||
Write-Host " Schema: $($response.schema)" -ForegroundColor Gray
|
||||
} else {
|
||||
Write-Host " [FAIL] API responded but not successful" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
} catch {
|
||||
Write-Host " [FAIL] Cannot reach API: $($_.Exception.Message)" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
|
||||
# Test 2: INSERT new PC
|
||||
Write-Host "Test 2: INSERT New PC Record" -ForegroundColor Yellow
|
||||
$testHostname = "TEST-PS-" + (Get-Random -Minimum 1000 -Maximum 9999)
|
||||
$testSerial = "SER-" + (Get-Random -Minimum 100000 -Maximum 999999)
|
||||
|
||||
try {
|
||||
$postData = @{
|
||||
action = 'updateCompleteAsset'
|
||||
hostname = $testHostname
|
||||
serialNumber = $testSerial
|
||||
manufacturer = 'Dell'
|
||||
model = 'OptiPlex 7090'
|
||||
pcType = 'Standard'
|
||||
loggedInUser = 'testuser'
|
||||
osVersion = 'Windows 10 Pro'
|
||||
}
|
||||
|
||||
$response = Invoke-RestMethod -Uri $DashboardURL -Method Post -Body $postData -TimeoutSec 30
|
||||
|
||||
if ($response.success) {
|
||||
Write-Host " [OK] PC record created successfully" -ForegroundColor Green
|
||||
Write-Host " Hostname: $testHostname" -ForegroundColor Gray
|
||||
Write-Host " Machine ID: $($response.machineid)" -ForegroundColor Gray
|
||||
Write-Host " Operation: $($response.operation)" -ForegroundColor Gray
|
||||
$machineId = $response.machineid
|
||||
} else {
|
||||
Write-Host " [FAIL] Failed to create PC: $($response.error)" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
} catch {
|
||||
Write-Host " [FAIL] Error creating PC: $($_.Exception.Message)" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
|
||||
# Test 3: UPDATE existing PC
|
||||
Write-Host "Test 3: UPDATE Existing PC Record" -ForegroundColor Yellow
|
||||
$updatedSerial = "SER-UPDATED-" + (Get-Random -Minimum 100000 -Maximum 999999)
|
||||
|
||||
try {
|
||||
$postData = @{
|
||||
action = 'updateCompleteAsset'
|
||||
hostname = $testHostname
|
||||
serialNumber = $updatedSerial
|
||||
manufacturer = 'Dell'
|
||||
model = 'OptiPlex 7090'
|
||||
pcType = 'Engineer' # Changed type
|
||||
loggedInUser = 'updateduser'
|
||||
osVersion = 'Windows 10 Enterprise'
|
||||
}
|
||||
|
||||
$response = Invoke-RestMethod -Uri $DashboardURL -Method Post -Body $postData -TimeoutSec 30
|
||||
|
||||
if ($response.success) {
|
||||
Write-Host " [OK] PC record updated successfully" -ForegroundColor Green
|
||||
Write-Host " Hostname: $testHostname" -ForegroundColor Gray
|
||||
Write-Host " Machine ID: $($response.machineid)" -ForegroundColor Gray
|
||||
Write-Host " Serial Updated: $updatedSerial" -ForegroundColor Gray
|
||||
} else {
|
||||
Write-Host " [FAIL] Failed to update PC: $($response.error)" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
} catch {
|
||||
Write-Host " [FAIL] Error updating PC: $($_.Exception.Message)" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
|
||||
# Test 4: INSERT Shopfloor PC with network interfaces
|
||||
Write-Host "Test 4: INSERT Shopfloor PC with Network Data" -ForegroundColor Yellow
|
||||
$shopfloorHostname = "SHOPFLOOR-TEST-" + (Get-Random -Minimum 1000 -Maximum 9999)
|
||||
$shopfloorSerial = "SER-SF-" + (Get-Random -Minimum 100000 -Maximum 999999)
|
||||
|
||||
try {
|
||||
$networkInterfaces = @(
|
||||
@{
|
||||
InterfaceName = "Ethernet0"
|
||||
IPAddress = "192.168.1.100"
|
||||
SubnetMask = 24
|
||||
MACAddress = "00-11-22-33-44-55"
|
||||
IsDHCP = 0
|
||||
IsMachineNetwork = 1
|
||||
},
|
||||
@{
|
||||
InterfaceName = "Ethernet1"
|
||||
IPAddress = "10.48.130.50"
|
||||
SubnetMask = 24
|
||||
MACAddress = "00-11-22-33-44-66"
|
||||
IsDHCP = 1
|
||||
IsMachineNetwork = 0
|
||||
}
|
||||
) | ConvertTo-Json -Compress
|
||||
|
||||
$postData = @{
|
||||
action = 'updateCompleteAsset'
|
||||
hostname = $shopfloorHostname
|
||||
serialNumber = $shopfloorSerial
|
||||
manufacturer = 'Dell'
|
||||
model = 'OptiPlex 7060'
|
||||
pcType = 'Shopfloor'
|
||||
loggedInUser = 'shopfloor'
|
||||
osVersion = 'Windows 10 Enterprise LTSC'
|
||||
machineNo = 'M123'
|
||||
networkInterfaces = $networkInterfaces
|
||||
}
|
||||
|
||||
$response = Invoke-RestMethod -Uri $DashboardURL -Method Post -Body $postData -TimeoutSec 30
|
||||
|
||||
if ($response.success) {
|
||||
Write-Host " [OK] Shopfloor PC created with network data" -ForegroundColor Green
|
||||
Write-Host " Hostname: $shopfloorHostname" -ForegroundColor Gray
|
||||
Write-Host " Machine ID: $($response.machineid)" -ForegroundColor Gray
|
||||
Write-Host " Network Interfaces: $($response.data.networkInterfaces)" -ForegroundColor Gray
|
||||
Write-Host " Machine No: M123" -ForegroundColor Gray
|
||||
} else {
|
||||
Write-Host " [FAIL] Failed to create shopfloor PC: $($response.error)" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
} catch {
|
||||
Write-Host " [FAIL] Error creating shopfloor PC: $($_.Exception.Message)" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host "All Tests PASSED!" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "Summary:" -ForegroundColor Yellow
|
||||
Write-Host " - API connectivity verified" -ForegroundColor White
|
||||
Write-Host " - INSERT operations working" -ForegroundColor White
|
||||
Write-Host " - UPDATE operations working" -ForegroundColor White
|
||||
Write-Host " - Shopfloor PC with network data working" -ForegroundColor White
|
||||
Write-Host " - Phase 2 schema validated" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Reference in New Issue
Block a user