Skip to content

Commit

Permalink
Add credential support
Browse files Browse the repository at this point in the history
  • Loading branch information
PrzemyslawKlys committed Apr 9, 2024
1 parent 244c8e6 commit 21a5613
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Public/Computers/Get-ComputerInstalledUpdates.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
'Servicing Stack Update',
'Other'
)][string[]] $ExcludeType,
[string] $SearchKB
[string] $SearchKB,
[pscredential] $Credential
)
# https://learn.microsoft.com/en-us/windows/win32/api/wuapi/
<#
Expand Down Expand Up @@ -121,14 +122,29 @@
$Data = if ($Computers.Count -gt 0) {
foreach ($Computer in $Computers) {
try {
Invoke-Command -ComputerName $Computer -ScriptBlock $ScriptBlock -ErrorAction Stop | Select-Object -Property $Properties
$invokeCommandSplat = @{
ComputerName = $Computer
ScriptBlock = $ScriptBlock
ErrorAction = 'Stop'
}
if ($Credential) {
$invokeCommandSplat.Credential = $Credential
}
Invoke-Command @invokeCommandSplat | Select-Object -Property $Properties
} catch {
Write-Warning -Message "Get-ComputerInstalledUpdates - No data for computer $Computer. Failed with error: $($_.Exception.Message)"
}
}
} else {
try {
Invoke-Command -ScriptBlock $ScriptBlock -ErrorAction Stop
$invokeCommandSplat = @{
ScriptBlock = $ScriptBlock
ErrorAction = 'Stop'
}
if ($Credential) {
$invokeCommandSplat.Credential = $Credential
}
Invoke-Command @invokeCommandSplat
} catch {
Write-Warning -Message "Get-ComputerInstalledUpdates - No data for computer $($Env:COMPUTERNAME). Failed with error: $($_.Exception.Message)"
}
Expand Down

0 comments on commit 21a5613

Please sign in to comment.