Public/Invoke-NSPM365ExchangeRead.ps1
|
function Invoke-NSPM365ExchangeRead { <# .SYNOPSIS Dispatches an allowed read command through a uniquely selected Exchange command module. .DESCRIPTION Revalidates tenant, connection, prefix and module on each call. Does not authenticate. CommandInfo invocation avoids shadowed global functions and cross-session fallback. Bound Parameters still define the evidence scope; this is not a sandbox for arbitrary callers. .EXAMPLE Invoke-NSPM365ExchangeRead -TenantId $tenant -ConnectionId $id -CommandName Get-Mailbox -Parameters @{Identity='user@contoso.com'} #> [CmdletBinding()] param( [Parameter(Mandatory)][guid]$TenantId, [string]$ConnectionId, [Parameter(Mandatory)][ValidateSet('Get-Mailbox','Get-InboxRule','Get-AcceptedDomain','Get-MailboxPermission','Get-RecipientPermission','Get-MessageTraceV2','Get-MessageTraceDetailV2')][string]$CommandName, [hashtable]$Parameters = @{} ) if ($TenantId -eq [guid]::Empty) { throw 'TenantId cannot be empty.' } $connection = Get-NSPInvestigationExchangeConnection -TenantId $TenantId -ConnectionId $ConnectionId $command = Get-NSPInvestigationExchangeCommand -Connection $connection -CommandName $CommandName $invoke = @{} foreach ($key in $Parameters.Keys) { $invoke[$key] = $Parameters[$key] } $invoke.ErrorAction = 'Stop' & $command @invoke } |