Files
powershell-scripts/remote-execution/INSTRUCTIONS.txt
cproudlock 86b32d8597 Add fixnetworkshare, winrm-setup-package, udc remote-execution suites
- NetworkDriveManager.ps1: S: drive repair utility
- winrm-setup-package: Invoke-RemoteTask helper + Setup-WinRM.bat + HTML guide
- remote-execution/udc: UDC_Update.ps1 and batch wrappers for updating
  DNC controllers on shop-floor PCs
- Invoke-RemoteMaintenance.ps1: substantial rework (~1650 lines)
- Schedule-Maintenance and complete-asset minor updates
- Bump edncfix gitlink to v1.6.0 (2748bfa)
- .gitignore: block inventory.csv/xlsx (CUI) and logs_*.txt (per-host logs)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 12:04:40 -04:00

154 lines
5.6 KiB
Plaintext

============================================================
Schedule-Maintenance.ps1 - Documentation
============================================================
Wrapper script that stores credentials securely and
runs Invoke-RemoteMaintenance.ps1 unattended or on a
schedule via Windows Task Scheduler.
============================================================
REQUIREMENTS
============================================================
- PowerShell 5.1+
- Run as Administrator (required for scheduling only)
- ALL scripts must be in the SAME folder:
Invoke-RemoteMaintenance.ps1
Schedule-Maintenance.ps1
Export-PCList.ps1
shopfloor-pcs.txt (or your PC list file)
============================================================
PARAMETERS
============================================================
-SaveCredential Save credentials for unattended use
-Username Domain\username (use with -SaveCredential)
-Password Password (use with -SaveCredential)
-Task Maintenance task name (e.g. Reboot)
-ComputerListFile Path to text file with PC hostnames
-CreateScheduledTask Register a Windows Scheduled Task
-TaskFrequency Daily, Weekly, or Once (default: Weekly)
-TaskDay Day of week (default: Sunday)
-TaskTime Time in HH:mm format (default: 03:00)
-TaskDate Specific date for Once (e.g. 2026-02-22)
============================================================
STEP 1: Save Credentials (one time)
============================================================
.\Schedule-Maintenance.ps1 -SaveCredential -Username "DS\570005354" -Password "MyP@ssw0rd"
- Encrypted with AES-256 key
- Works from normal or admin PowerShell
- Stored in .creds\ folder (not plaintext)
- Re-run if your password changes
============================================================
STEP 2: Generate PC List
============================================================
# All shopfloor PCs from API
.\Export-PCList.ps1
# Filter by type
.\Export-PCList.ps1 -PcType Shopfloor
# Single PC for testing
"G63TVG04ESF" | Out-File -FilePath ".\test-reboot.txt" -Encoding UTF8
============================================================
STEP 3: Run or Schedule
============================================================
RUN IMMEDIATELY (no admin needed):
.\Schedule-Maintenance.ps1 -ComputerListFile ".\shopfloor-pcs.txt" -Task Reboot
SCHEDULE ONE-TIME (admin required):
.\Schedule-Maintenance.ps1 -CreateScheduledTask -ComputerListFile ".\shopfloor-pcs.txt" -Task Reboot -TaskFrequency Once -TaskTime "00:01" -TaskDate "2026-02-22"
SCHEDULE RECURRING (admin required):
.\Schedule-Maintenance.ps1 -CreateScheduledTask -ComputerListFile ".\shopfloor-pcs.txt" -Task Reboot -TaskFrequency Weekly -TaskDay Sunday -TaskTime "00:01"
============================================================
CHECKING RESULTS
============================================================
AFTER A SCHEDULED RUN:
Get-Content ".\logs\LAST-RUN-SUMMARY.txt"
FULL LOG (most recent):
Get-ChildItem ".\logs\" -Filter "maintenance-*-Reboot.log" | Sort-Object LastWriteTime -Descending | Select-Object -First 1 | Get-Content
CHECK IF TASK RAN:
Get-ScheduledTask -TaskName "ShopfloorMaintenance-Reboot" | Get-ScheduledTaskInfo
LastTaskResult = 0 means success
Anything else means it errored before writing logs
LOGS LOCATION:
.\logs\ (inside your scripts folder)
============================================================
MANAGING SCHEDULED TASKS
============================================================
# List maintenance tasks
Get-ScheduledTask | Where-Object { $_.TaskName -like "ShopfloorMaintenance*" }
# Run now (don't wait for schedule)
Start-ScheduledTask -TaskName "ShopfloorMaintenance-Reboot"
# Delete a task
Unregister-ScheduledTask -TaskName "ShopfloorMaintenance-Reboot"
# Or use: Task Scheduler GUI (taskschd.msc)
============================================================
AVAILABLE TASKS
============================================================
Reboot, DISM, SFC, OptimizeDisk, DiskCleanup,
ClearUpdateCache, ClearBrowserCache, RestartSpooler,
FlushDNS, RestartWinRM, SetTimezone, SyncTime,
UpdateEMxAuthToken, DeployUDCWebServerConfig,
UpdateDNCMXHosts,
InstallDashboard, InstallLobbyDisplay,
UninstallDashboard, UninstallLobbyDisplay
============================================================
TROUBLESHOOTING
============================================================
"No saved credentials found"
-> .\Schedule-Maintenance.ps1 -SaveCredential -Username "DS\user" -Password "pass"
"Access is denied" when scheduling
-> Right-click PowerShell -> Run as Administrator
"No credentials provided. Exiting."
-> Use -Username and -Password flags instead of GUI prompt
No logs folder / empty logs
-> Task may not have run yet. Check:
Get-ScheduledTask -TaskName "ShopfloorMaintenance-Reboot" | Get-ScheduledTaskInfo
Password changed
-> .\Schedule-Maintenance.ps1 -SaveCredential -Username "DS\user" -Password "newpass"
NOTE ABOUT "Running as AEROAD\SSO":
This is normal. The scheduled task runs as your Windows login.
It still uses your SAVED credentials for WinRM connections
to the remote shopfloor PCs. Two separate accounts:
1. Your Windows login = runs the script
2. Saved credentials = connects to remote PCs