Skip to content

Commit bdcaf59

Browse files
committed
Improve MessageData handling in Write-Information override
The Write-Information override now checks for the presence of MessageData in PSBoundParameters before processing and calling the original function. This prevents unnecessary calls when MessageData is not provided.
1 parent daf52fb commit bdcaf59

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Modules/CIPPCore/Public/Tools/Enable-CippConsoleLogging.ps1

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ function Enable-CippConsoleLogging {
4444
[string[]]$Tags
4545
)
4646

47-
# Send to telemetry
48-
if ($MessageData -and -not [string]::IsNullOrWhiteSpace(($MessageData | Out-String).Trim())) {
49-
Send-CippConsoleLog -Message ($MessageData | Out-String).Trim() -Level 'Information'
47+
# Only process and call original if MessageData is provided
48+
if ($PSBoundParameters.ContainsKey('MessageData') -and $MessageData) {
49+
# Send to telemetry
50+
if (-not [string]::IsNullOrWhiteSpace(($MessageData | Out-String).Trim())) {
51+
Send-CippConsoleLog -Message ($MessageData | Out-String).Trim() -Level 'Information'
52+
}
53+
54+
# Call original function
55+
Microsoft.PowerShell.Utility\Write-Information @PSBoundParameters
5056
}
51-
52-
# Call original function
53-
Microsoft.PowerShell.Utility\Write-Information @PSBoundParameters
5457
}
5558

5659
# Override Write-Warning

0 commit comments

Comments
 (0)