Consolidate all PowerShell scripts and fix production issues
Scripts added to shopdb/scripts/: - Backup-GERegistry.ps1 - Get-InstalledApps.ps1 - Install-AssetCollectionSchedule.ps1 - Setup-WinRM.ps1 - Test-API-Connection.ps1 Updates to existing scripts: - Update-PC-Minimal.ps1: Added SSL bypass, added 8003 to Part Marker machines - Update-ShopfloorPCs-Remote.ps1: Added SSL bypass, added 8003 to Part Marker machines Part Marker machine numbers now include: 0612, 0613, 0615, 8003 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
277
scripts/Backup-GERegistry.ps1
Normal file
277
scripts/Backup-GERegistry.ps1
Normal file
@@ -0,0 +1,277 @@
|
||||
# Backup-GERegistry.ps1
|
||||
# Backs up GE Aircraft Engines registry keys from both 32-bit and 64-bit locations
|
||||
# Saves to S:\dt\adata\script\backup with naming: [machinenumber-]serialnumber-date.reg
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$BackupPath = "S:\dt\adata\script\backup",
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[switch]$Silent = $false
|
||||
)
|
||||
|
||||
# Function to write colored output (only if not silent)
|
||||
function Write-ColorOutput {
|
||||
param(
|
||||
[string]$Message,
|
||||
[string]$Color = "White"
|
||||
)
|
||||
if (-not $Silent) {
|
||||
Write-Host $Message -ForegroundColor $Color
|
||||
}
|
||||
}
|
||||
|
||||
# Function to get machine number from registry
|
||||
function Get-MachineNumber {
|
||||
$machineNumber = $null
|
||||
|
||||
# Check GE Aircraft Engines registry paths for MachineNo
|
||||
$gePaths = @(
|
||||
"HKLM:\Software\GE Aircraft Engines\DNC\General",
|
||||
"HKLM:\Software\WOW6432Node\GE Aircraft Engines\DNC\General"
|
||||
)
|
||||
|
||||
foreach ($path in $gePaths) {
|
||||
if (Test-Path $path) {
|
||||
try {
|
||||
$regKey = Get-ItemProperty -Path $path -ErrorAction SilentlyContinue
|
||||
if ($regKey.MachineNo) {
|
||||
$machineNumber = $regKey.MachineNo
|
||||
Write-ColorOutput " Found MachineNo in registry: $machineNumber" "Green"
|
||||
break
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-ColorOutput " Could not read MachineNo from $path" "Yellow"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# If not found in registry, try hostname pattern matching
|
||||
if (-not $machineNumber) {
|
||||
$hostname = $env:COMPUTERNAME
|
||||
if ($hostname -match '(\d{4})') {
|
||||
$machineNumber = $matches[1]
|
||||
Write-ColorOutput " Extracted machine number from hostname: $machineNumber" "Cyan"
|
||||
}
|
||||
}
|
||||
|
||||
return $machineNumber
|
||||
}
|
||||
|
||||
# Function to get serial number
|
||||
function Get-SerialNumber {
|
||||
$serialNumber = $null
|
||||
|
||||
try {
|
||||
# Get serial number from WMI
|
||||
$bios = Get-WmiObject Win32_BIOS
|
||||
if ($bios.SerialNumber -and $bios.SerialNumber -ne "To be filled by O.E.M.") {
|
||||
$serialNumber = $bios.SerialNumber
|
||||
Write-ColorOutput " Found serial number: $serialNumber" "Green"
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-ColorOutput " Could not retrieve serial number from BIOS" "Yellow"
|
||||
}
|
||||
|
||||
# If no serial number, use computer name as fallback
|
||||
if (-not $serialNumber) {
|
||||
$serialNumber = $env:COMPUTERNAME
|
||||
Write-ColorOutput " Using computer name as identifier: $serialNumber" "Cyan"
|
||||
}
|
||||
|
||||
return $serialNumber
|
||||
}
|
||||
|
||||
# Function to export registry key
|
||||
function Export-RegistryKey {
|
||||
param(
|
||||
[string]$RegistryPath,
|
||||
[string]$OutputFile,
|
||||
[string]$Description
|
||||
)
|
||||
|
||||
# Convert PowerShell path to reg.exe format
|
||||
$regPath = $RegistryPath -replace 'HKLM:', 'HKEY_LOCAL_MACHINE'
|
||||
|
||||
try {
|
||||
# Use reg export command
|
||||
$result = reg export "$regPath" "$OutputFile" /y 2>&1
|
||||
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-ColorOutput " ✓ Exported $Description" "Green"
|
||||
return $true
|
||||
} else {
|
||||
Write-ColorOutput " ✗ Failed to export $Description" "Red"
|
||||
Write-ColorOutput " Error: $result" "Red"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-ColorOutput " ✗ Exception exporting $Description`: $_" "Red"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
# Main script
|
||||
Write-ColorOutput "`n=== GE Aircraft Engines Registry Backup ===" "Cyan"
|
||||
Write-ColorOutput "Starting registry backup process..." "White"
|
||||
|
||||
# Get machine number and serial number
|
||||
Write-ColorOutput "`nGathering system information:" "Yellow"
|
||||
$machineNumber = Get-MachineNumber
|
||||
$serialNumber = Get-SerialNumber
|
||||
|
||||
# Create backup filename
|
||||
$dateStamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||
if ($machineNumber) {
|
||||
$backupFileName = "${machineNumber}-${serialNumber}-${dateStamp}.reg"
|
||||
} else {
|
||||
$backupFileName = "${serialNumber}-${dateStamp}.reg"
|
||||
}
|
||||
|
||||
# Create backup directory if it doesn't exist
|
||||
if (-not (Test-Path $BackupPath)) {
|
||||
try {
|
||||
New-Item -ItemType Directory -Path $BackupPath -Force | Out-Null
|
||||
Write-ColorOutput "`nCreated backup directory: $BackupPath" "Green"
|
||||
}
|
||||
catch {
|
||||
Write-ColorOutput "`nFailed to create backup directory: $_" "Red"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Define registry paths to backup
|
||||
$registryPaths = @{
|
||||
'64bit' = @{
|
||||
Path = 'HKLM:\SOFTWARE\GE Aircraft Engines'
|
||||
Description = 'GE Aircraft Engines (64-bit)'
|
||||
OutputFile = Join-Path $BackupPath "64bit-$backupFileName"
|
||||
}
|
||||
'32bit' = @{
|
||||
Path = 'HKLM:\SOFTWARE\WOW6432Node\GE Aircraft Engines'
|
||||
Description = 'GE Aircraft Engines (32-bit on 64-bit system)'
|
||||
OutputFile = Join-Path $BackupPath "32bit-$backupFileName"
|
||||
}
|
||||
}
|
||||
|
||||
# Backup registries
|
||||
Write-ColorOutput "`nBacking up GE Aircraft Engines registry keys:" "Yellow"
|
||||
$backupResults = @()
|
||||
|
||||
foreach ($type in $registryPaths.Keys) {
|
||||
$regInfo = $registryPaths[$type]
|
||||
|
||||
Write-ColorOutput "`n Checking $($regInfo.Description)..." "White"
|
||||
|
||||
if (Test-Path $regInfo.Path) {
|
||||
Write-ColorOutput " Found registry key at: $($regInfo.Path)" "Green"
|
||||
|
||||
$success = Export-RegistryKey -RegistryPath $regInfo.Path `
|
||||
-OutputFile $regInfo.OutputFile `
|
||||
-Description $regInfo.Description
|
||||
|
||||
if ($success -and (Test-Path $regInfo.OutputFile)) {
|
||||
$fileSize = (Get-Item $regInfo.OutputFile).Length
|
||||
$fileSizeKB = [math]::Round($fileSize / 1KB, 2)
|
||||
Write-ColorOutput " Saved to: $($regInfo.OutputFile) (${fileSizeKB} KB)" "Green"
|
||||
|
||||
$backupResults += @{
|
||||
Type = $type
|
||||
File = $regInfo.OutputFile
|
||||
Size = $fileSizeKB
|
||||
Success = $true
|
||||
}
|
||||
} else {
|
||||
$backupResults += @{
|
||||
Type = $type
|
||||
File = $regInfo.OutputFile
|
||||
Success = $false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Write-ColorOutput " Registry key not found: $($regInfo.Path)" "Yellow"
|
||||
Write-ColorOutput " Skipping $type backup" "Yellow"
|
||||
}
|
||||
}
|
||||
|
||||
# Combined backup (both 32-bit and 64-bit in one file)
|
||||
Write-ColorOutput "`nCreating combined backup:" "Yellow"
|
||||
$combinedFile = Join-Path $BackupPath $backupFileName
|
||||
$combinedContent = @()
|
||||
|
||||
# Add header
|
||||
$combinedContent += "Windows Registry Editor Version 5.00"
|
||||
$combinedContent += ""
|
||||
$combinedContent += "; GE Aircraft Engines Registry Backup"
|
||||
$combinedContent += "; Machine: $machineNumber"
|
||||
$combinedContent += "; Serial: $serialNumber"
|
||||
$combinedContent += "; Date: $dateStamp"
|
||||
$combinedContent += "; Computer: $env:COMPUTERNAME"
|
||||
$combinedContent += ""
|
||||
|
||||
# Merge successful backups
|
||||
$mergedCount = 0
|
||||
foreach ($result in $backupResults | Where-Object { $_.Success }) {
|
||||
if (Test-Path $result.File) {
|
||||
Write-ColorOutput " Merging $($result.Type) backup..." "White"
|
||||
|
||||
# Read the file and skip the header
|
||||
$content = Get-Content $result.File
|
||||
if ($content.Count -gt 1) {
|
||||
# Skip the "Windows Registry Editor Version 5.00" line
|
||||
$contentToAdd = $content | Select-Object -Skip 1
|
||||
|
||||
$combinedContent += "; === $($result.Type) Registry ==="
|
||||
$combinedContent += $contentToAdd
|
||||
$combinedContent += ""
|
||||
$mergedCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($mergedCount -gt 0) {
|
||||
try {
|
||||
# Save combined file
|
||||
$combinedContent | Out-File -FilePath $combinedFile -Encoding Unicode
|
||||
|
||||
$fileSize = (Get-Item $combinedFile).Length
|
||||
$fileSizeKB = [math]::Round($fileSize / 1KB, 2)
|
||||
|
||||
Write-ColorOutput " ✓ Combined backup saved: $combinedFile (${fileSizeKB} KB)" "Green"
|
||||
|
||||
# Clean up individual files if combined was successful
|
||||
foreach ($result in $backupResults | Where-Object { $_.Success }) {
|
||||
if (Test-Path $result.File) {
|
||||
Remove-Item $result.File -Force
|
||||
Write-ColorOutput " Cleaned up temporary file: $($result.Type)" "Gray"
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-ColorOutput " ✗ Failed to create combined backup: $_" "Red"
|
||||
}
|
||||
} else {
|
||||
Write-ColorOutput " ✗ No registry keys were successfully backed up" "Red"
|
||||
}
|
||||
|
||||
# Summary
|
||||
Write-ColorOutput "`n=== Backup Summary ===" "Cyan"
|
||||
Write-ColorOutput "Machine Number: $(if ($machineNumber) { $machineNumber } else { 'Not found' })" "White"
|
||||
Write-ColorOutput "Serial Number: $serialNumber" "White"
|
||||
Write-ColorOutput "Backup Location: $BackupPath" "White"
|
||||
Write-ColorOutput "Backup File: $backupFileName" "White"
|
||||
|
||||
$successCount = ($backupResults | Where-Object { $_.Success }).Count
|
||||
$totalCount = $backupResults.Count
|
||||
|
||||
if ($successCount -gt 0) {
|
||||
Write-ColorOutput "`nBackup completed: $successCount of $totalCount registries backed up successfully" "Green"
|
||||
} else {
|
||||
Write-ColorOutput "`nNo GE Aircraft Engines registry keys found to backup" "Yellow"
|
||||
}
|
||||
|
||||
# Return success status
|
||||
exit $(if ($successCount -gt 0) { 0 } else { 1 })
|
||||
5
scripts/Get-InstalledApps.ps1
Normal file
5
scripts/Get-InstalledApps.ps1
Normal file
@@ -0,0 +1,5 @@
|
||||
Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" |
|
||||
Where-Object { $_.DisplayName } |
|
||||
Select-Object DisplayName, DisplayVersion, Publisher |
|
||||
Sort-Object DisplayName |
|
||||
Format-Table -AutoSize
|
||||
111
scripts/Install-AssetCollectionSchedule.ps1
Normal file
111
scripts/Install-AssetCollectionSchedule.ps1
Normal file
@@ -0,0 +1,111 @@
|
||||
# Install-AssetCollectionSchedule.ps1
|
||||
# Creates a Windows scheduled task to run asset collection 4 times daily in the background
|
||||
|
||||
param(
|
||||
[string]$ScriptPath = "S:\DT\adata\script\Update-PC-CompleteAsset-Silent.bat",
|
||||
[string]$TaskName = "GE Asset Collection",
|
||||
[string]$TaskDescription = "Automated PC asset collection for GE shopfloor systems - runs silently 4 times daily"
|
||||
)
|
||||
|
||||
Write-Host "===================================== " -ForegroundColor Cyan
|
||||
Write-Host "GE Asset Collection - Schedule Installer" -ForegroundColor Cyan
|
||||
Write-Host "===================================== " -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Check if running as administrator
|
||||
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||
Write-Host "[ERROR] This script must be run as Administrator to create scheduled tasks" -ForegroundColor Red
|
||||
Write-Host "Please right-click and 'Run as Administrator'" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Verify the script file exists
|
||||
if (-not (Test-Path $ScriptPath)) {
|
||||
Write-Host "[ERROR] Asset collection script not found at: $ScriptPath" -ForegroundColor Red
|
||||
Write-Host "Please ensure the script is deployed to the correct location" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Installing scheduled task for automated asset collection..." -ForegroundColor Green
|
||||
Write-Host " Script Path: $ScriptPath" -ForegroundColor Gray
|
||||
Write-Host " Task Name: $TaskName" -ForegroundColor Gray
|
||||
Write-Host " Frequency: 4 times daily (every 6 hours)" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
|
||||
try {
|
||||
# Remove existing task if it exists
|
||||
$existingTask = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue
|
||||
if ($existingTask) {
|
||||
Write-Host "Removing existing scheduled task..." -ForegroundColor Yellow
|
||||
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
|
||||
}
|
||||
|
||||
# Define the action - run the batch file completely hidden
|
||||
$action = New-ScheduledTaskAction -Execute "cmd.exe" -Argument "/c `"$ScriptPath`"" -WorkingDirectory "S:\DT\adata\script"
|
||||
|
||||
# Define multiple triggers for 4 times daily (6:00 AM, 12:00 PM, 6:00 PM, 12:00 AM)
|
||||
$trigger1 = New-ScheduledTaskTrigger -Daily -At "06:00"
|
||||
$trigger2 = New-ScheduledTaskTrigger -Daily -At "12:00"
|
||||
$trigger3 = New-ScheduledTaskTrigger -Daily -At "18:00"
|
||||
$trigger4 = New-ScheduledTaskTrigger -Daily -At "00:00"
|
||||
|
||||
# Define settings - run in background, don't disturb users
|
||||
$settings = New-ScheduledTaskSettingsSet `
|
||||
-AllowStartIfOnBatteries `
|
||||
-DontStopIfGoingOnBatteries `
|
||||
-StartWhenAvailable `
|
||||
-RunOnlyIfNetworkAvailable `
|
||||
-DontStopOnIdleEnd `
|
||||
-Hidden `
|
||||
-Priority 4 `
|
||||
-ExecutionTimeLimit (New-TimeSpan -Hours 2) `
|
||||
-RestartCount 3 `
|
||||
-RestartInterval (New-TimeSpan -Minutes 10)
|
||||
|
||||
# Run as SYSTEM account for maximum permissions and no user interaction
|
||||
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
|
||||
|
||||
# Create the scheduled task
|
||||
$task = New-ScheduledTask -Action $action -Trigger @($trigger1, $trigger2, $trigger3, $trigger4) -Settings $settings -Principal $principal -Description $TaskDescription
|
||||
|
||||
# Register the task
|
||||
Register-ScheduledTask -TaskName $TaskName -InputObject $task -Force
|
||||
|
||||
Write-Host "[SUCCESS] Scheduled task created successfully!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Task Details:" -ForegroundColor Cyan
|
||||
Write-Host " Name: $TaskName" -ForegroundColor Gray
|
||||
Write-Host " Schedule: 4 times daily at 6:00 AM, 12:00 PM, 6:00 PM, 12:00 AM" -ForegroundColor Gray
|
||||
Write-Host " Account: SYSTEM (runs in background)" -ForegroundColor Gray
|
||||
Write-Host " Hidden: Yes (no user interruption)" -ForegroundColor Gray
|
||||
Write-Host " Network Required: Yes" -ForegroundColor Gray
|
||||
Write-Host " Max Runtime: 2 hours" -ForegroundColor Gray
|
||||
Write-Host " Auto Restart: 3 attempts if failed" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
|
||||
# Test the task by running it once
|
||||
Write-Host "Testing scheduled task..." -ForegroundColor Yellow
|
||||
Start-ScheduledTask -TaskName $TaskName
|
||||
|
||||
Start-Sleep -Seconds 3
|
||||
|
||||
$taskInfo = Get-ScheduledTaskInfo -TaskName $TaskName
|
||||
Write-Host " Last Run: $($taskInfo.LastRunTime)" -ForegroundColor Gray
|
||||
Write-Host " Last Result: $($taskInfo.LastTaskResult)" -ForegroundColor Gray
|
||||
Write-Host " Next Run: $($taskInfo.NextRunTime)" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
|
||||
Write-Host "[INFO] Task installation complete!" -ForegroundColor Green
|
||||
Write-Host "The asset collection will now run automatically 4 times daily in the background." -ForegroundColor Green
|
||||
Write-Host "Users will not see any windows or be interrupted during execution." -ForegroundColor Green
|
||||
|
||||
} catch {
|
||||
Write-Host "[ERROR] Failed to create scheduled task: $($_.Exception.Message)" -ForegroundColor Red
|
||||
Write-Host "Please check Windows Event Viewer for additional details" -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "===================================== " -ForegroundColor Cyan
|
||||
Write-Host "Installation Complete" -ForegroundColor Cyan
|
||||
Write-Host "===================================== " -ForegroundColor Cyan
|
||||
186
scripts/Setup-WinRM.ps1
Normal file
186
scripts/Setup-WinRM.ps1
Normal file
@@ -0,0 +1,186 @@
|
||||
#Requires -RunAsAdministrator
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sets up WinRM configuration for remote asset collection.
|
||||
|
||||
.DESCRIPTION
|
||||
This script configures WinRM settings to enable remote PowerShell execution
|
||||
for asset collection across shopfloor computers.
|
||||
|
||||
.PARAMETER TrustedHosts
|
||||
Comma-separated list of trusted hosts (IP addresses or computer names).
|
||||
Use "*" to trust all hosts (less secure but simpler).
|
||||
|
||||
.PARAMETER TestConnection
|
||||
Test WinRM connection to specified computers after setup.
|
||||
|
||||
.EXAMPLE
|
||||
.\Setup-WinRM.ps1 -TrustedHosts "10.48.130.100,10.48.130.101"
|
||||
|
||||
.EXAMPLE
|
||||
.\Setup-WinRM.ps1 -TrustedHosts "*"
|
||||
|
||||
.NOTES
|
||||
Author: System Administrator
|
||||
Date: 2025-09-26
|
||||
Version: 1.0
|
||||
#>
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$TrustedHosts = "",
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string[]]$TestConnection = @()
|
||||
)
|
||||
|
||||
function Show-WinRMStatus {
|
||||
Write-Host "=== Current WinRM Configuration ===" -ForegroundColor Cyan
|
||||
|
||||
try {
|
||||
$winrmStatus = Get-Service WinRM
|
||||
Write-Host "WinRM Service Status: $($winrmStatus.Status)" -ForegroundColor $(if($winrmStatus.Status -eq 'Running') {'Green'} else {'Red'})
|
||||
|
||||
$listeners = winrm enumerate winrm/config/listener
|
||||
Write-Host "WinRM Listeners: $($listeners.Count) configured" -ForegroundColor Gray
|
||||
|
||||
$trustedHosts = (Get-Item WSMan:\localhost\Client\TrustedHosts).Value
|
||||
Write-Host "Current Trusted Hosts: $trustedHosts" -ForegroundColor Gray
|
||||
|
||||
} catch {
|
||||
Write-Host "Error checking WinRM status: $($_.Exception.Message)" -ForegroundColor Red
|
||||
}
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
function Enable-WinRMConfiguration {
|
||||
param([string]$TrustedHosts)
|
||||
|
||||
Write-Host "=== Configuring WinRM ===" -ForegroundColor Cyan
|
||||
|
||||
try {
|
||||
# Enable PowerShell Remoting
|
||||
Write-Host "Enabling PowerShell Remoting..." -ForegroundColor Yellow
|
||||
Enable-PSRemoting -Force -SkipNetworkProfileCheck
|
||||
Write-Host "[OK] PowerShell Remoting enabled" -ForegroundColor Green
|
||||
|
||||
# Start WinRM service
|
||||
Write-Host "Starting WinRM service..." -ForegroundColor Yellow
|
||||
Start-Service WinRM
|
||||
Set-Service WinRM -StartupType Automatic
|
||||
Write-Host "[OK] WinRM service started and set to automatic" -ForegroundColor Green
|
||||
|
||||
# Configure trusted hosts if specified
|
||||
if (-not [string]::IsNullOrEmpty($TrustedHosts)) {
|
||||
Write-Host "Setting trusted hosts to: $TrustedHosts" -ForegroundColor Yellow
|
||||
Set-Item WSMan:\localhost\Client\TrustedHosts -Value $TrustedHosts -Force
|
||||
Write-Host "[OK] Trusted hosts configured" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[SKIP] No trusted hosts specified" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Configure firewall
|
||||
Write-Host "Configuring Windows Firewall..." -ForegroundColor Yellow
|
||||
try {
|
||||
Set-NetFirewallRule -DisplayName "Windows Remote Management (HTTP-In)" -Enabled True
|
||||
Write-Host "[OK] Firewall rule enabled" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "[WARN] Could not configure firewall rule: $($_.Exception.Message)" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Set authentication
|
||||
Write-Host "Configuring authentication..." -ForegroundColor Yellow
|
||||
Set-Item WSMan:\localhost\Service\Auth\Basic -Value $true
|
||||
Set-Item WSMan:\localhost\Service\Auth\CredSSP -Value $true
|
||||
Write-Host "[OK] Authentication configured" -ForegroundColor Green
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "WinRM configuration completed successfully!" -ForegroundColor Green
|
||||
|
||||
} catch {
|
||||
Write-Host "Error configuring WinRM: $($_.Exception.Message)" -ForegroundColor Red
|
||||
return $false
|
||||
}
|
||||
|
||||
return $true
|
||||
}
|
||||
|
||||
function Test-WinRMConnections {
|
||||
param([string[]]$Computers)
|
||||
|
||||
if ($Computers.Count -eq 0) {
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host "=== Testing WinRM Connections ===" -ForegroundColor Cyan
|
||||
|
||||
$credential = Get-Credential -Message "Enter credentials for testing remote connections"
|
||||
if (-not $credential) {
|
||||
Write-Host "No credentials provided for testing" -ForegroundColor Yellow
|
||||
return
|
||||
}
|
||||
|
||||
foreach ($computer in $Computers) {
|
||||
Write-Host "Testing connection to $computer..." -NoNewline
|
||||
|
||||
try {
|
||||
$session = New-PSSession -ComputerName $computer -Credential $credential -ErrorAction Stop
|
||||
Remove-PSSession $session
|
||||
Write-Host " [OK]" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host " [FAIL] $($_.Exception.Message)" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
function Show-NextSteps {
|
||||
Write-Host "=== Next Steps ===" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "1. Ensure target computers have WinRM enabled:" -ForegroundColor Yellow
|
||||
Write-Host " Run this script on each target computer:" -ForegroundColor White
|
||||
Write-Host " .\Setup-WinRM.ps1" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host "2. Create your computer list file:" -ForegroundColor Yellow
|
||||
Write-Host " Copy shopfloor-pcs-example.txt to shopfloor-pcs.txt" -ForegroundColor White
|
||||
Write-Host " Edit the file to include your actual computer IP addresses" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host "3. Test connections:" -ForegroundColor Yellow
|
||||
Write-Host " .\Invoke-RemoteAssetCollection.ps1 -ComputerList @('10.48.130.100') -TestConnections" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host "4. Run asset collection:" -ForegroundColor Yellow
|
||||
Write-Host " .\Invoke-RemoteAssetCollection.ps1 -ComputerListFile .\shopfloor-pcs.txt" -ForegroundColor Gray
|
||||
Write-Host " or" -ForegroundColor White
|
||||
Write-Host " .\Run-RemoteCollection.bat" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
# Main execution
|
||||
try {
|
||||
Write-Host "=== WinRM Setup Script ===" -ForegroundColor Cyan
|
||||
Write-Host "Date: $(Get-Date)" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
|
||||
# Show current status
|
||||
Show-WinRMStatus
|
||||
|
||||
# Configure WinRM
|
||||
$success = Enable-WinRMConfiguration -TrustedHosts $TrustedHosts
|
||||
|
||||
if ($success) {
|
||||
# Show updated status
|
||||
Show-WinRMStatus
|
||||
|
||||
# Test connections if requested
|
||||
if ($TestConnection.Count -gt 0) {
|
||||
Test-WinRMConnections -Computers $TestConnection
|
||||
}
|
||||
|
||||
# Show next steps
|
||||
Show-NextSteps
|
||||
}
|
||||
|
||||
} catch {
|
||||
Write-Host "Fatal error: $($_.Exception.Message)" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
170
scripts/Test-API-Connection.ps1
Normal file
170
scripts/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 ""
|
||||
@@ -1,6 +1,25 @@
|
||||
# Minimal PC data collection script
|
||||
# For locked-down PCs with restricted permissions
|
||||
|
||||
# SSL/TLS Certificate Bypass for HTTPS connections
|
||||
try {
|
||||
if (-not ([System.Management.Automation.PSTypeName]'TrustAllCertsPolicy').Type) {
|
||||
Add-Type @"
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
public class TrustAllCertsPolicy : ICertificatePolicy {
|
||||
public bool CheckValidationResult(
|
||||
ServicePoint srvPoint, X509Certificate certificate,
|
||||
WebRequest request, int certificateProblem) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
"@
|
||||
}
|
||||
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
|
||||
} catch { }
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
|
||||
$apiUrl = "https://tsgwp00525.rd.ds.ge.com/shopdb/api.asp"
|
||||
$logFile = "$env:TEMP\shopdb-update.log"
|
||||
|
||||
@@ -149,6 +168,7 @@ try {
|
||||
"^0612$" = "Part Marker" # Part markers
|
||||
"^0613$" = "Part Marker" # Part markers
|
||||
"^0615" = "Part Marker" # Part markers
|
||||
"^8003$" = "Part Marker" # Part markers
|
||||
"^TEST" = $null # Test machines - no type hint
|
||||
"^TEMP" = $null # Temporary - no type hint
|
||||
"^DEFAULT"= $null # Default value - no type hint
|
||||
|
||||
@@ -75,6 +75,25 @@ param(
|
||||
[switch]$WhatIf
|
||||
)
|
||||
|
||||
# SSL/TLS Certificate Bypass for HTTPS connections
|
||||
try {
|
||||
if (-not ([System.Management.Automation.PSTypeName]'TrustAllCertsPolicy').Type) {
|
||||
Add-Type @"
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
public class TrustAllCertsPolicy : ICertificatePolicy {
|
||||
public bool CheckValidationResult(
|
||||
ServicePoint srvPoint, X509Certificate certificate,
|
||||
WebRequest request, int certificateProblem) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
"@
|
||||
}
|
||||
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
|
||||
} catch { }
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
|
||||
#region Functions
|
||||
|
||||
function Write-Log {
|
||||
@@ -408,6 +427,7 @@ function Get-RemotePCInfo {
|
||||
"^0612$" = "Part Marker" # Part markers
|
||||
"^0613$" = "Part Marker" # Part markers
|
||||
"^0615" = "Part Marker" # Part markers
|
||||
"^8003$" = "Part Marker" # Part markers
|
||||
"^TEST" = $null # Test machines
|
||||
"^TEMP" = $null # Temporary
|
||||
"^DEFAULT"= $null # Default value
|
||||
|
||||
Reference in New Issue
Block a user