ken_nogi/PAD/Install-SoftwareSequentially.ps1
Kenichiro NOGI 88a402ce0f up
2026-07-10 18:13:30 +09:00

73 lines
2.6 KiB
PowerShell

param(
[string]$SoftwareDir = (Join-Path -Path $PSScriptRoot -ChildPath 'Software')
)
$ErrorActionPreference = 'Stop'
if (-not (Test-Path -LiteralPath $SoftwareDir -PathType Container)) {
Write-Error "Software folder was not found: $SoftwareDir"
exit 1
}
$successDir = Join-Path -Path $SoftwareDir -ChildPath 'Success'
$failedDir = Join-Path -Path $SoftwareDir -ChildPath 'Failed'
New-Item -Path $successDir -ItemType Directory -Force | Out-Null
New-Item -Path $failedDir -ItemType Directory -Force | Out-Null
$targetExtensions = @('.exe', '.msi', '.msix', '.msixbundle')
$installers = Get-ChildItem -LiteralPath $SoftwareDir -File |
Where-Object { $targetExtensions -contains $_.Extension.ToLowerInvariant() } |
Sort-Object -Property Name
if (-not $installers) {
Write-Host "No installer files were found under: $SoftwareDir"
exit 0
}
foreach ($installer in $installers) {
Write-Host "Starting installer: $($installer.Name)"
$exitCode = $null
try {
if ($installer.Extension.Equals('.msi', [System.StringComparison]::OrdinalIgnoreCase)) {
$argList = @('/i', $installer.FullName)
$proc = Start-Process -FilePath 'msiexec.exe' -ArgumentList $argList -Wait -PassThru -NoNewWindow
$exitCode = $proc.ExitCode
}
else {
$proc = Start-Process -FilePath $installer.FullName -Wait -PassThru
$exitCode = $proc.ExitCode
}
}
catch {
Write-Warning "Failed to launch installer: $($installer.Name)"
Write-Warning $_.Exception.Message
$exitCode = -1
}
$confirmation = Read-Host "Press Enter to mark SUCCESS and continue. Type anything and press Enter to mark FAILURE"
$isSuccess = [string]::IsNullOrWhiteSpace($confirmation)
$destinationRoot = if ($isSuccess) { $successDir } else { $failedDir }
$destinationPath = Join-Path -Path $destinationRoot -ChildPath $installer.Name
if (Test-Path -LiteralPath $destinationPath) {
$base = [System.IO.Path]::GetFileNameWithoutExtension($installer.Name)
$ext = $installer.Extension
$timestamp = Get-Date -Format 'yyyyMMdd_HHmmss'
$destinationPath = Join-Path -Path $destinationRoot -ChildPath ("{0}_{1}{2}" -f $base, $timestamp, $ext)
}
Move-Item -LiteralPath $installer.FullName -Destination $destinationPath -Force
if ($isSuccess) {
Write-Host "Success: $($installer.Name) (ExitCode=$exitCode, ManualConfirm=Enter)"
}
else {
Write-Warning "Failed: $($installer.Name) (ExitCode=$exitCode, ManualConfirm=NonEnter)"
}
}
Write-Host 'All installer processing has finished.'