1

I've noticed something new with PowerShell 7.4.4 and MicroSoftTeams Module 6.1.0+ and errors.

I've been writing and maintaining a PowerShell script that uses the MST PS Module to log in and manage certain aspects of the MST Tenant. This has been ongoing for several years now, and all's right in the world. I handle all of the errors that the MST module throws with my own routines and log those to disk via my logging function. Recently, I've noticed a new addition: a Correlation ID being regurgitated with every error. For example, this command:

$script:sipDomains = (Get-CsTenant -ErrorAction SilentlyContinue -ErrorVariable myError   ).SipDomain | Out-Null
$myError | Format-List -Force

when given a valid login to the MST tenant that does not have access to the Get-CsTenant command, generates this error:

Correlation id for this request : 6ddc5d19-6413-4aff-a78b-99946a33640c

Exception             : Microsoft.Teams.ConfigAPI.Cmdlets.Generated.Runtime.RestException`1[Microsoft.Teams.ConfigAPI.Cmdlets.Generated.Mod
                        els.IApiError]: Access Denied.
TargetObject          : { Select = , Defaultpropertyset = Extended }
CategoryInfo          : InvalidOperation: ({ Select = , Defaul…rtyset = Extended }:<>f__AnonymousType67`2) [Get-CsTenant], RestException`1
FullyQualifiedErrorId : Forbidden,Microsoft.Teams.ConfigApi.Cmdlets.GetCsTenant
ErrorDetails          : Access Denied.
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at Get-CsTenantObou<Process>, C:\Users\P1332365\OneDrive -
                        Optus\Documents\PowerShell\Modules\MicrosoftTeams\6.1.0\internal\Merged_internal.ps1: line 15927
                        at Get-CsTenantPoint<Process>, C:\Users\P1332365\OneDrive -
                        Optus\Documents\PowerShell\Modules\MicrosoftTeams\6.1.0\custom\Merged_custom_PsExt.ps1: line 2983
                        at Get-CsTenantPoint<Process>, C:\Users\P1332365\OneDrive -
                        Optus\Documents\PowerShell\Modules\MicrosoftTeams\6.1.0\exports\ProxyCmdletDefinitionsWithHelp.ps1: line 44992
                        at Get-CsTenant<Process>, C:\Users\P1332365\OneDrive -
                        Optus\Documents\PowerShell\Modules\MicrosoftTeams\6.1.0\exports\ProxyCmdletDefinitionsWithHelp.ps1: line 11327
                        at <ScriptBlock>, C:\Temp\OptusPS_Tools\OMEGA\omega.ps1: line 1017
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}
PSMessageDetails      :

I can handle the error information; the Correlation ID, I can not suppress nor hide. It messes up the display of my script and makes a right sloppy mess of the screen overall.

Can anyone tell me anything about this? I believe it has something to do with logging and being able to use the GUID to look through maybe windows events or something, but I'm not really interested in that.

My ask here is how to block the display of the Correlation ID on an error from a PowerShell cmdlet

6
  • 1
    Did you try -ErrorAction SilentlyContinue or embedding it in a Try/Catch block? Commented Jul 31, 2024 at 6:11
  • Yes to both. Either way, it handles everything other than the Correlation ID, which is always displays on the console Commented Jul 31, 2024 at 8:01
  • As a diagnostic step, if you comment out the $myError | Format-List -Force do you still see the correlation id line in the output? (In other words, is it a property of the error variable, or something being written out by Get-CsTenant) Commented Jul 31, 2024 at 14:45
  • And the trailing | Out-Null on your first line seems a bit out of place. You’d normally only use that to suppress uncaptured output, but you’re already capturing the value into a variable. Commented Jul 31, 2024 at 14:48
  • @mclayton, yes, the Correlation ID still prints to the screen, which can be very misleading if you're set to -ErrorAction SilentlyContinue, as it may appear that something happened but for no apparent reason. Also, I've removed the | Out-Null as I was desperately trying anything. Commented Aug 1, 2024 at 3:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.