Auto-apply startup items from profile, Configure-PC -MachineNumberOnly
Three changes to eliminate the redundant startup-item picker during the imaging chain: 06-OrganizeDesktop.ps1 - new Phase 3: auto-apply startup items Reads pcProfile.startupItems (or site-wide default) and creates .lnk files in AllUsers Startup folder. Supports exe, existing, and url types (same as Configure-PC). Idempotent - skips items that already exist so manual changes aren't overwritten. Runs during shopfloor setup finalization, so the tech doesn't need to select startup items again. Configure-PC.ps1 - new -MachineNumberOnly switch When set, skips the entire startup-items section and only shows the machine number prompt (if UDC/eDNC at 9999). Used by sync_intune -AsTask after completion. Full startup picker still available when the tech opens Configure-PC.bat manually from the desktop. Monitor-IntuneProgress.ps1 - simplified -AsTask completion After post-reboot DSC complete: unregisters task, launches Configure-PC -MachineNumberOnly, exits. Tech uses sync_intune.bat on the desktop to see QR code for inventory purposes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -488,15 +488,83 @@ Write-Host "=== Phase 2: populate Shopfloor Tools with app shortcuts ==="
|
|||||||
Add-ShopfloorToolsApps
|
Add-ShopfloorToolsApps
|
||||||
|
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "=== Phase 3: remove empty category folders ==="
|
Write-Host "=== Phase 3: auto-apply startup items from PC profile ==="
|
||||||
|
# Creates .lnk files in AllUsers Startup folder based on the profile's
|
||||||
|
# startupItems. This is the auto-apply step that eliminates the need
|
||||||
|
# for Configure-PC to ask about startup items during the imaging chain.
|
||||||
|
# Configure-PC.bat on the desktop still lets the tech modify them later.
|
||||||
|
$startupDir = 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup'
|
||||||
|
|
||||||
|
$cfgStartup = if ($pcProfile -and $pcProfile.startupItems) { $pcProfile.startupItems }
|
||||||
|
elseif ($siteConfig -and $siteConfig.startupItems) { $siteConfig.startupItems }
|
||||||
|
else { $null }
|
||||||
|
|
||||||
|
if ($cfgStartup -and $cfgStartup.Count -gt 0) {
|
||||||
|
if (-not (Test-Path $startupDir)) {
|
||||||
|
New-Item -ItemType Directory -Path $startupDir -Force | Out-Null
|
||||||
|
}
|
||||||
|
$edgePath = @(
|
||||||
|
'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe',
|
||||||
|
'C:\Program Files\Microsoft\Edge\Application\msedge.exe'
|
||||||
|
) | Where-Object { Test-Path -LiteralPath $_ } | Select-Object -First 1
|
||||||
|
|
||||||
|
foreach ($si in $cfgStartup) {
|
||||||
|
$lnkPath = Join-Path $startupDir "$($si.label).lnk"
|
||||||
|
# Skip if already exists (idempotent - don't overwrite user changes)
|
||||||
|
if (Test-Path -LiteralPath $lnkPath) {
|
||||||
|
Write-Host " exists: $($si.label)"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch ($si.type) {
|
||||||
|
'exe' {
|
||||||
|
if (Test-Path -LiteralPath $si.target) {
|
||||||
|
if (New-ShopfloorLnk -Path $lnkPath -Target $si.target) {
|
||||||
|
Write-Host " added: $($si.label)"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host " skip: $($si.label) - target not installed" -ForegroundColor DarkGray
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'existing' {
|
||||||
|
$src = Find-ExistingLnk $si.sourceLnk
|
||||||
|
if ($src) {
|
||||||
|
try {
|
||||||
|
Copy-Item -LiteralPath $src -Destination $lnkPath -Force
|
||||||
|
Write-Host " added: $($si.label)"
|
||||||
|
} catch { Write-Warning " failed: $($si.label) - $_" }
|
||||||
|
} else {
|
||||||
|
Write-Host " skip: $($si.label) - source not found" -ForegroundColor DarkGray
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'url' {
|
||||||
|
$url = $null
|
||||||
|
if ($si.urlKey -and $siteConfig -and $siteConfig.urls) {
|
||||||
|
$url = $siteConfig.urls.$($si.urlKey)
|
||||||
|
}
|
||||||
|
if ($url -and $edgePath) {
|
||||||
|
if (New-ShopfloorLnk -Path $lnkPath -Target $edgePath -Arguments "--new-window `"$url`"") {
|
||||||
|
Write-Host " added: $($si.label)"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host " skip: $($si.label) - URL or Edge not available" -ForegroundColor DarkGray
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Host " (no startup items in profile)"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "=== Phase 4: remove empty category folders ==="
|
||||||
Remove-EmptyCategoryFolders
|
Remove-EmptyCategoryFolders
|
||||||
|
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "=== Phase 4: Edge default browser + startup tabs ==="
|
Write-Host "=== Phase 5: Edge default browser + startup tabs ==="
|
||||||
Invoke-EdgeDefaultBrowser
|
Invoke-EdgeDefaultBrowser
|
||||||
|
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "=== Phase 5: register logon sweeper scheduled task ==="
|
Write-Host "=== Phase 6: register logon sweeper scheduled task ==="
|
||||||
Register-SweepScheduledTask -ScriptPath $scriptPath
|
Register-SweepScheduledTask -ScriptPath $scriptPath
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
@@ -15,6 +15,13 @@
|
|||||||
#
|
#
|
||||||
# Run via Configure-PC.bat on the SupportUser desktop.
|
# Run via Configure-PC.bat on the SupportUser desktop.
|
||||||
|
|
||||||
|
param(
|
||||||
|
# When set, only show the machine number section (skip startup items).
|
||||||
|
# Used by sync_intune -AsTask after completion -- startup items are
|
||||||
|
# already auto-applied by 06-OrganizeDesktop from the PC profile.
|
||||||
|
[switch]$MachineNumberOnly
|
||||||
|
)
|
||||||
|
|
||||||
$ErrorActionPreference = 'Continue'
|
$ErrorActionPreference = 'Continue'
|
||||||
|
|
||||||
# --- Transcript logging ---
|
# --- Transcript logging ---
|
||||||
@@ -307,6 +314,9 @@ if ($needsMachineNumber) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# --- Section 2: Startup items + machine-number logon task ---
|
# --- Section 2: Startup items + machine-number logon task ---
|
||||||
|
# Skipped when -MachineNumberOnly (called from sync_intune -AsTask after
|
||||||
|
# completion -- startup items already auto-applied by 06-OrganizeDesktop).
|
||||||
|
if (-not $MachineNumberOnly) {
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host " AUTO-STARTUP ITEMS" -ForegroundColor Yellow
|
Write-Host " AUTO-STARTUP ITEMS" -ForegroundColor Yellow
|
||||||
Write-Host " ----------------------------------------"
|
Write-Host " ----------------------------------------"
|
||||||
@@ -423,6 +433,8 @@ if ($selection) {
|
|||||||
Write-Host " No changes." -ForegroundColor DarkGray
|
Write-Host " No changes." -ForegroundColor DarkGray
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} # end if (-not $MachineNumberOnly)
|
||||||
|
|
||||||
# --- Summary ---
|
# --- Summary ---
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host " CURRENT STATE" -ForegroundColor Cyan
|
Write-Host " CURRENT STATE" -ForegroundColor Cyan
|
||||||
|
|||||||
@@ -560,15 +560,17 @@ function Invoke-SetupComplete {
|
|||||||
Write-Host "The post-reboot DSC install phase is finished. The device is ready."
|
Write-Host "The post-reboot DSC install phase is finished. The device is ready."
|
||||||
|
|
||||||
if ($AsTask) {
|
if ($AsTask) {
|
||||||
# Task mode: unregister our own scheduled task, launch Configure-PC
|
# Task mode: unregister our own scheduled task
|
||||||
Write-Host "Unregistering sync task..." -ForegroundColor Cyan
|
Write-Host "Unregistering sync task..." -ForegroundColor Cyan
|
||||||
try {
|
try {
|
||||||
Unregister-ScheduledTask -TaskName 'Shopfloor Intune Sync' -Confirm:$false -ErrorAction SilentlyContinue
|
Unregister-ScheduledTask -TaskName 'Shopfloor Intune Sync' -Confirm:$false -ErrorAction SilentlyContinue
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
|
# Machine number prompt only (startup items are auto-applied by
|
||||||
|
# 06-OrganizeDesktop from the PC profile). Tech can re-open
|
||||||
|
# sync_intune.bat manually to see QR code for inventory.
|
||||||
if ($ConfigureScript -and (Test-Path -LiteralPath $ConfigureScript)) {
|
if ($ConfigureScript -and (Test-Path -LiteralPath $ConfigureScript)) {
|
||||||
Write-Host "Launching Configure-PC..." -ForegroundColor Cyan
|
try { & $ConfigureScript -MachineNumberOnly } catch { Write-Warning "Configure-PC failed: $_" }
|
||||||
try { & $ConfigureScript } catch { Write-Warning "Configure-PC failed: $_" }
|
|
||||||
}
|
}
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user