Skip to content

Commit

Permalink
win: improve output/user feedback capabilities
Browse files Browse the repository at this point in the history
- Improve error handling.
- Provide more detailed user feedback with meaningful messages.
- Check if capability exists before performing operations.
- Inform system restart is needed.
  • Loading branch information
undergroundwires committed Aug 4, 2023
1 parent ff84f56 commit c705452
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/application/collections/windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7359,10 +7359,44 @@ functions:
call:
function: RunPowerShell
parameters:
code: Get-WindowsCapability -Online -Name '{{ $capabilityName }}*' | Remove-WindowsCapability -Online
code: |-
$capabilityName = '{{ $capabilityName }}'
try {
# Using wildcard for version number handling
$capability = Get-WindowsCapability -Online -Name "$capabilityName*"
if (!$capability) {
Write-Host "Skipping. Capability `"$capabilityName`" is missing."
exit 0
}
if ($capability.State -eq 'NotPresent') {
Write-Host "Skipping. Capability `"$capabilityName`" is missing."
exit 0
}
Write-Host "Removing capability `"$capabilityName`""
Remove-WindowsCapability -Online -Name "$($capability.Name)" -ErrorAction Stop
Write-Host "Successfully removed `"$CapabilityName`""
}
catch {
Write-Error "Failed to remove `"$capabilityName`": $_"
}
revertCode: |-
$capability = Get-WindowsCapability -Online -Name '{{ $capabilityName }}*'
Add-WindowsCapability -Name "$capability.Name" -Online
$capabilityName = '{{ $capabilityName }}'
try {
# Using wildcard for version number handling
$capability = Get-WindowsCapability -Online -Name "$capabilityName*"
if (!$capability) {
Write-Error "Failed to find `"$capabilityName`"."
exit 1
}
$result = Add-WindowsCapability -Name $capability.Name -Online -ErrorAction Stop
Write-Host "Successfully added `"$capabilityName`"."
if ($result.RestartNeeded -eq 'Yes') {
Write-Warning "A restart is needed to finish installing `"$capabilityName`"."
}
}
catch {
Write-Error "Failed to add `"$capabilityName`": $_"
}
-
name: RenameSystemFile
parameters:
Expand Down

0 comments on commit c705452

Please sign in to comment.