Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Tasks/git-clone/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,22 @@ function InstallPackage{
$process.WaitForExit()
$installExitCode = $process.ExitCode
if ($installExitCode -ne 0) {
Write-Error "Failed to install $PackageId with Install-WinGetPackage, error code $($installExitCode)."
# this was the last try, so exit with the install exit code
exit $installExitCode
if ($PsInstallScope -eq "CurrentUser") {
# try executing the commandlet via Start-Process instead of using Invoke-CimMethod, as this works better in some cases
$process = Start-Process -FilePath "C:\Program Files\PowerShell\7\pwsh.exe" -ArgumentList "-Command $($installPackageCommand)" -PassThru
$handle = $process.Handle # cache process.Handle so ExitCode isn't null when we need it below
$process.WaitForExit()
$installExitCode = $process.ExitCode
if ($installExitCode -ne 0) {
Write-Error "Failed to install package. Exit code: $($installExitCode)."
exit $installExitCode
}
}
else {
Write-Error "Failed to install $PackageId with Install-WinGetPackage, error code $($installExitCode)."
# this was the last try, so exit with the install exit code
exit $installExitCode
}
}

# read the output file and write it to the console
Expand Down
34 changes: 30 additions & 4 deletions Tasks/winget/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,21 @@ else {
$process.WaitForExit()
$installExitCode = $process.ExitCode
if ($installExitCode -ne 0) {
Write-Error "Failed to install package. Exit code: $($installExitCode)."
exit 1
if ($PsInstallScope -eq "CurrentUser") {
# try executing the commandlet via Start-Process instead of using Invoke-CimMethod, as this works better in some cases
$process = Start-Process -FilePath "C:\Program Files\PowerShell\7\pwsh.exe" -ArgumentList "-Command $($installPackageCommand)" -PassThru
$handle = $process.Handle # cache process.Handle so ExitCode isn't null when we need it below
$process.WaitForExit()
$installExitCode = $process.ExitCode
if ($installExitCode -ne 0) {
Write-Error "Failed to install package. Exit code: $($installExitCode)."
exit 2
}
}
else {
Write-Error "Failed to install package. Exit code: $($installExitCode)."
exit 1
}
}

# read the output file and write it to the console
Expand Down Expand Up @@ -430,8 +443,21 @@ else {
$process.WaitForExit()
$installExitCode = $process.ExitCode
if ($installExitCode -ne 0) {
Write-Error "Failed to run configuration file installation. Exit code: $($installExitCode)."
exit 1
if ($PsInstallScope -eq "CurrentUser") {
# try executing the commandlet via Start-Process instead of using Invoke-CimMethod, as this works better in some cases
$process = Start-Process -FilePath "C:\Program Files\PowerShell\7\pwsh.exe" -ArgumentList "-Command $($applyConfigCommand)" -PassThru
$handle = $process.Handle # cache process.Handle so ExitCode isn't null when we need it below
$process.WaitForExit()
$installExitCode = $process.ExitCode
if ($installExitCode -ne 0) {
Write-Error "Failed to run configuration file installation. Exit code: $($installExitCode)."
exit 2
}
}
else {
Write-Error "Failed to run configuration file installation. Exit code: $($installExitCode)."
exit 1
}
}

# read the output file and write it to the console
Expand Down
Loading