< Back

Get-MgaMailMessage

Sat Jan 18, 2020 4:41 pm

NAME Get-MgaMailMessage



SYNOPSIS

Retrieves messages from a email folder from Exchange Online using the graph api.





SYNTAX

Get-MgaMailMessage [[-InputObject] <MessageOrFolderParameter[]>] [-User <String>] [-Subject <String>] [-Delta]

[-ResultSize <Int64>] [-Token <AzureAccessToken>] [<CommonParameters>]



Get-MgaMailMessage [[-FolderName] <String[]>] [-User <String>] [-Subject <String>] [-Delta] [-ResultSize <Int64>]

[-Token <AzureAccessToken>] [<CommonParameters>]





DESCRIPTION

Retrieves messages from a email folder from Exchange Online using the graph api.





PARAMETERS

-InputObject <MessageOrFolderParameter[]>

Carrier object for Pipeline input

Accepts messages or folders from other Mga-functions



Required? false

Position? 1

Default value

Accept pipeline input? true (ByValue, ByPropertyName)

Accept wildcard characters? false



-FolderName <String[]>

The display name of the folder to search.

Defaults to the inbox.



Required? false

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-User <String>

The user-account to access. Defaults to the main user connected as.

Can be any primary email name of any user the connected token has access to.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Subject <String>

The subject to filter by (Client Side filtering)



Required? false

Position? named

Default value *

Accept pipeline input? false

Accept wildcard characters? false



-Delta [<SwitchParameter>]

Indicates a "delta-query" for incremental changes on mails.

The switch allows you to query mutliple times against the same user and folder while only getting additional,

updated or deleted messages.



Please notice, that delta queries needs to be handeled right. See the examples for correct usage.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-ResultSize <Int64>

The user to execute this under. Defaults to the user the token belongs to.



Required? false

Position? named

Default value (Get-PSFConfigValue -FullName 'MSGraph.Query.ResultSize' -Fallback 100)

Accept pipeline input? false

Accept wildcard characters? false



-Token <AzureAccessToken>

The token representing an established connection to the Microsoft Graph Api.

Can be created by using New-MgaAccessToken.

Can be omitted if a connection has been registered using the -Register parameter on New-MgaAccessToken.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS

MSGraph.Exchange.Mail.Message





-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Get-MgaMailMessage



Return emails in the inbox of the user connected to through a token.









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>$mails = Get-MgaMailMessage -Delta



Return emails in the inbox of the user connected to through a token and write the output in the variable $mails.

IMPORTANT, the -Delta switch needs to be specified on the first call, because the outputobject will has to be piped

into the next delta query.



The content of $mails can be used and processed:

PS C:\\> $mails



So the second Get-MgaMailMessage call has to be:

PS C:\\> $deltaMails = Get-MgaMailMessage -InputObject $mails -Delta



This return only unqueried, updated, or new messages from the previous call and writes the result in the

variable $deltaMails.



The content of the $deltaMails variable can be used as output and should only overwrites the $mail variable if

there is content in $deltaMails:

PS C:\\> if($deltaMails) {

$mails = $deltaMails

$deltaMails

}



From the second call, the procedure can be continued as needed, only updates will be outputted by

Get-MgaMailMessage.









-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Get-MgaMailFolder -Name "Junkemail" | Get-MgaMailMessage



Return emails from the Junkemail folder of the user connected to through a token.









-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Get-MgaMailMessage -FolderName "MyFolder" -Subject "Important*"



Return emails where the subject starts with "Important" from the folder "MyFolder" of the user connected to

through a token.











RELATED LINKS