Creates or retrieves a mail-enabled security group with a custom or default domain.
The New-MailEnabledSendingGroup function ensures that a mail-enabled security group is available for restricting email sending in Exchange Online. If a group of the specified name already exists and is security-enabled, the function returns that group. Otherwise, it creates a new security-enabled distribution group. You can specify either a custom primary SMTP address (via the 'CustomDomain' parameter set) or construct one using an alias and default domain (via the 'DefaultDomain' parameter set). By default, the 'CustomDomain' parameter set is used. If you wish to construct the SMTP address from the alias, switch to the 'DefaultDomain' parameter set.
New-MailEnabledSendingGroup -Name <String> [-Alias <String>] -PrimarySmtpAddress <String> [-LogOutputPath <String>] [-WhatIf] [-Confirm] [<CommonParameters>] New-MailEnabledSendingGroup -Name <String> [-Alias <String>] -DefaultDomain <String> [-LogOutputPath <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
The name of the mail-enabled security group to create or retrieve. This is also used as the alias if no separate Alias parameter is provided. |
true | false | |||
An optional alias for the group. If omitted, the group name is used as the alias. |
false | false | |||
(CustomDomain parameter set) The full SMTP address for the group (e.g. "MyGroup@contoso.com"). This parameter is mandatory when using the 'CustomDomain' parameter set. |
true | false | |||
(DefaultDomain parameter set) The domain portion to be appended to the group alias (e.g. "Alias@DefaultDomain"). This parameter is mandatory when using the 'DefaultDomain' parameter set. |
true | false | |||
An optional path to output the log file. If not provided, logs will not be written to a file. |
false | false | |||
wi | false | false | |||
cf | false | false |
The input type is the type of the objects that you can pipe to the cmdlet.
The output type is the type of the objects that the cmdlet emits.
New-MailEnabledSendingGroup -Name "SecureSenders" -DefaultDomain "contoso.com" Creates a new mail-enabled security group named "SecureSenders" with a primary SMTP address of SecureSenders@contoso.com.EXAMPLE 2
New-MailEnabledSendingGroup -Name "SecureSenders" -Alias "Senders" -PrimarySmtpAddress "Senders@customdomain.org" Creates a new mail-enabled security group named "SecureSenders" with an alias "Senders" and a primary SMTP address of Senders@customdomain.org.
Publishes a new or existing Graph Email App with specified configurations.
The Publish-TkEmailApp function creates or configures a Graph Email App in Azure AD. It supports two scenarios:
Publish-TkEmailApp [-AppPrefix <String>] -AuthorizedSenderUserName <String> -MailEnabledSendingGroup <String> [-CertPrefix <String>] [-CertThumbprint <String>] [-KeyExportPolicy <String>] [-VaultName <String>] [-OverwriteVaultSecret] [-ReturnParamSplat] [-DoNotUseDomainSuffix] [-LogOutput <String>] [-WhatIf] [-Confirm] [<CommonParameters>] Publish-TkEmailApp -ExistingAppObjectId <String> -CertPrefix <String> [-CertThumbprint <String>] [-KeyExportPolicy <String>] [-VaultName <String>] [-OverwriteVaultSecret] [-ReturnParamSplat] [-DoNotUseDomainSuffix] [-LogOutput <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
The prefix used to initialize the Graph Email App. Must be 2-4 characters, letters, and numbers only. Default is 'Gtk'. |
false | false | Gtk | ||
The username of the authorized sender. Must be a valid email address. |
true | false | |||
The mail-enabled security group. Must be a valid email address. |
true | false | |||
The AppId of the existing App Registration to which you want to attach a certificate. Must be a valid GUID. |
true | false | |||
Prefix to add to the certificate subject for the existing app. |
false | false | |||
The thumbprint of the certificate to be retrieved. Must be a valid 40-character hexadecimal string. |
false | false | |||
Key export policy for the certificate. Valid values are 'Exportable' and 'NonExportable'. Default is 'NonExportable'. |
false | false | NonExportable | ||
If specified, use a custom vault name. Otherwise, use the default 'GraphEmailAppLocalStore'. |
false | false | GraphEmailAppLocalStore | ||
If specified, overwrite the vault secret if it already exists. |
false | false | False | ||
If specified, return the parameter splat for use in other functions. |
false | false | False | ||
Switch to add session domain suffix to the app name. |
false | false | False | ||
If specified, log the output to the console. |
false | false | |||
wi | false | false | |||
cf | false | false |
# Permissions required for app registration: - 'Application.ReadWrite.All' - 'DelegatedPermissionGrant.ReadWrite.All' - 'Directory.ReadWrite.All' - 'RoleManagement.ReadWrite.Directory' # Permissions granted to the app: - 'Mail.Send' (Application) - Send mail as any user # Exchange application policy restricts send to a mail enabled security group # Ensure a mail enabled sending group is created first: $DefaultDomain = 'contoso.com' $MailEnabledSendingGroupToCreate = "CTSO-GraphAPIMail" # Creates a mail-enabled security group named "MySenders" using a default domain $group = New-MailEnabledSendingGroup -Name $MailEnabledSendingGroupToCreate -DefaultDomain $DefaultDomain # Create a new Graph Email App for a single tenant $LicensedUserToSendAs = 'helpdesk@contoso.com' Publish-TkEmailApp ` -AuthorizedSenderUserName $LicensedUserToSendAs ` -MailEnabledSendingGroup $group.PrimarySmtpAddress ` -ReturnParamSplat # Returns an app named like 'GraphToolKit-Gtk-<Session AD Domain>-As-helpdesk' # Returns a param splat that can be used as input for the send mail function: # Example: $params = @{ AppId = 'your-app-id' Id = 'your-app-object-id' AppName = 'GraphToolKit-Gtk-<Session AD Domain>-As-helpdesk' CertificateSubject = 'GraphToolKit-GTK-<Session AD Domain>-As-helpdesk' AppRestrictedSendGroup = 'CTSO-GraphAPIMail@contoso.com' CertExpires = 'yyyy-MM-dd HH:mm:ss' CertThumbprint = 'your-cert-thumbprint' ConsentUrl = 'https://login.microsoftonline.com/<your-tenant-id>/adminconsent?client_id=<your-app-id>' DefaultDomain = 'contoso.com' SendAsUser = 'helpdesk' SendAsUserEmail = 'helpdesk@contoso.com' TenantID = 'your-tenant-id' }EXAMPLE 2
# Create a multi client app registration where one app exists and multiple certificates are associated to the app: # Initial setup: # Create the group as before (or reuse the existing group) and run the following commands: $LicensedUserToSendAs = 'helpdesk@contoso.com' $CertPrefix = "CTSO" # First Company prefix. This will be used to prefix the certificate subject. Publish-TkEmailApp ` -CertPrefix $CertPrefix ` -AuthorizedSenderUserName $LicensedUserToSendAs ` -MailEnabledSendingGroup $group.PrimarySmtpAddress ` -ReturnParamSplat # Returns an app named like 'GraphToolKit-Gtk-<Session AD Domain>-As-helpdesk' $params = @{ AppId = 'your-app-id' Id = 'your-app-object-id' AppName = 'GraphToolKit-Gtk-<Session AD Domain>-As-helpdesk' CertificateSubject = 'GraphToolKit-CTSO-<Session AD Domain>-As-helpdesk' AppRestrictedSendGroup = 'CTSO-GraphAPIMail@contoso.com' CertExpires = 'yyyy-MM-dd HH:mm:ss' CertThumbprint = 'your-cert-thumbprint' ConsentUrl = 'https://login.microsoftonline.com/<your-tenant-id>/adminconsent?client_id=<your-app-id>' DefaultDomain = 'contoso.com' SendAsUser = 'helpdesk' SendAsUserEmail = 'helpdesk@contoso.com' TenantID = 'your-tenant-id' } $useExistingParams = @{ ExistingAppObjectId = $params.Id CertPrefix = 'NewCompany' OverwriteVaultSecret = $true # optional, if you want to overwrite the existing vault secret ReturnParamSplat = $true # optional, returns the param splat } Publish-TkEmailApp @useExistingParams # The new Cert will be prefixed with the new company prefix and will allow the current client to authenticate. # Back in the app registrations console, if you look at the internal notes in the properties of the app: # The app's "Internal Notes" will be populated with the following json: # Assists in tracking the app's usage and configuration. { "GraphEmailAppFor": "helpdesk@contoso.com", "RestrictedToGroup": "CTSO-GraphAPIMail@contoso.com", "AppPermissions": "Mail.Send", "New-Company_ClientIP": "<Public IP Address of the client where the app was called>", "New-Company_Host": "<Host of the client where the app was called>", "NewCoolCompany_ClientIP": "<Public IP Address of the client where the app was called>", "NewCoolCompany_Host": "Host of the client where the app was called>" } # New cert additions added through the toolkit will append new client info to these notes.
Publishes (creates) a new M365 Audit App registration in Entra ID (Azure AD) with a specified certificate.
The Publish-TkM365AuditApp function creates a new Azure AD application used for M365 auditing. It connects to Microsoft Graph, gathers the required permissions for SharePoint and Exchange, and optionally creates a self-signed certificate if no thumbprint is provided. It also assigns the application to the Exchange Administrator and Global Reader roles. By default, the newly created application details are stored as a secret in the specified SecretManagement vault.
Publish-TkM365AuditApp [[-AppPrefix] <String>] [[-CertThumbprint] <String>] [[-KeyExportPolicy] <String>] [[-VaultName] <String>] [-OverwriteVaultSecret] [-ReturnParamSplat] [-DoNotUseDomainSuffix] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
A short prefix (2-4 alphanumeric characters) used to build the app name. Defaults to "Gtk" if not specified. Example app name: GraphToolKit-MSN-GraphApp-MyDomain-As-helpDesk |
false | false | Gtk | ||
The thumbprint of an existing certificate in the current user's certificate store. If not provided, a new self-signed certificate is created. |
false | false | |||
Specifies whether the newly created certificate (if no thumbprint is provided) is 'Exportable' or 'NonExportable'. Defaults to 'NonExportable'. |
false | false | NonExportable | ||
The SecretManagement vault name in which to store the app credentials. Defaults to "M365AuditAppLocalStore" if not specified. |
false | false | M365AuditAppLocalStore | ||
If specified, overwrites an existing secret in the specified vault if it already exists. |
false | false | False | ||
If specified, returns a parameter splat string for use in other functions, instead of the default PSCustomObject containing the app details. |
false | false | False | ||
If specified, does not append the domain suffix to the app name. |
false | false | False |
The input type is the type of the objects that you can pipe to the cmdlet.
The output type is the type of the objects that the cmdlet emits.
Publish-TkM365AuditApp -AppPrefix "CS12" -ReturnParamSplat Creates a new M365 Audit App with the prefix "CS12", returns a parameter splat, and stores the credentials in the default vault.
Publishes a new MEM (Intune) Policy Manager App in Azure AD with read-only or read-write permissions.
The Publish-TkMemPolicyManagerApp function creates an Azure AD application intended for managing Microsoft Endpoint Manager (MEM/Intune) policies. It optionally creates or retrieves a certificate, configures the necessary Microsoft Graph permissions for read-only or read-write access, and stores the resulting app credentials in a SecretManagement vault.
Publish-TkMemPolicyManagerApp [-AppPrefix] <String> [[-CertThumbprint] <String>] [[-KeyExportPolicy] <String>] [[-VaultName] <String>] [-OverwriteVaultSecret] [-ReadWrite] [-ReturnParamSplat] [-DoNotUseDomainSuffix] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
A 2-4 character prefix used to build the application name (e.g., CORP, MSN). This helps uniquely identify the app in Azure AD. |
true | false | |||
The thumbprint of an existing certificate in the current user's certificate store. If omitted, a new self-signed certificate is created. |
false | false | |||
Specifies whether the newly created certificate is 'Exportable' or 'NonExportable'. Defaults to 'NonExportable' if not specified. |
false | false | NonExportable | ||
The name of the SecretManagement vault in which to store the app credentials. Defaults to 'MemPolicyManagerLocalStore'. |
false | false | MemPolicyManagerLocalStore | ||
If specified, overwrites any existing secret of the same name in the vault. |
false | false | False | ||
If specified, grants read-write MEM/Intune permissions. Otherwise, read-only permissions are granted. |
false | false | False | ||
If specified, returns a parameter splat string for use in other functions. Otherwise, returns a PSCustomObject containing the app details. |
false | false | False | ||
If specified, the function does not append the domain suffix to the app name. |
false | false | False |
The input type is the type of the objects that you can pipe to the cmdlet.
The output type is the type of the objects that the cmdlet emits.
Publish-TkMemPolicyManagerApp -AppPrefix "CORP" -ReadWrite Creates a new MEM Policy Manager App with read-write permissions, retrieves or creates a certificate, and stores the credentials in the default vault.
Sends an email using the Microsoft Graph API, either by retrieving app credentials from a local vault or by specifying them manually.
The Send-TkEmailAppMessage function uses the Microsoft Graph API to send an email to a specified recipient. It supports two parameter sets:
Send-TkEmailAppMessage -AppName <String> -To <String> -FromAddress <String> -Subject <String> -EmailBody <String> [-AttachmentPath <String[]>] [-VaultName <String>] [-WhatIf] [-Confirm] [<CommonParameters>] Send-TkEmailAppMessage -AppId <String> -TenantId <String> -CertThumbprint <String> -To <String> -FromAddress <String> -Subject <String> -EmailBody <String> [-AttachmentPath <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Name | Alias | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
[Vault Parameter Set Only] The name of the pre-created Microsoft Graph Email App (stored in GraphEmailAppLocalStore). Used only if the 'Vault' parameter set is chosen. The function retrieves the AppId, TenantId, and certificate thumbprint from the vault entry. |
true | false | |||
[Manual Parameter Set Only] The Azure AD application (client) ID to use for sending the email. Must be used together with TenantId and CertThumbprint in the 'Manual' parameter set. |
true | false | |||
[Manual Parameter Set Only] The Azure AD tenant ID (GUID or domain name). Must be used together with AppId and CertThumbprint in the 'Manual' parameter set. |
true | false | |||
[Manual Parameter Set Only] The certificate thumbprint (in Cert:\CurrentUser\My) used for authenticating as the Azure AD app. Must be used together with AppId and TenantId in the 'Manual' parameter set. |
true | false | |||
The email address of the recipient. |
true | false | |||
The email address of the sender who is authorized to send email as configured in the Graph Email App. |
true | false | |||
The subject line of the email. |
true | false | |||
The body text of the email. |
true | false | |||
An array of file paths for any attachments to include in the email. Each path must exist as a leaf file. |
false | false | |||
[Vault Parameter Set Only] The name of the vault to retrieve the GraphEmailApp object. Default is 'GraphEmailAppLocalStore'. |
false | false | GraphEmailAppLocalStore | ||
wi | false | false | |||
cf | false | false |
# Using the 'Vault' parameter set Send-TkEmailAppMessage -AppName "GraphEmailApp" -To "recipient@example.com" -FromAddress "sender@example.com" ` -Subject "Test Email" -EmailBody "This is a test email." Retrieves the app's credentials (AppId, TenantId, CertThumbprint) from the local vault under the secret name "GraphEmailApp" and sends an email.EXAMPLE 2
# Using the 'Manual' parameter set Send-TkEmailAppMessage -AppId "00000000-1111-2222-3333-444444444444" -TenantId "contoso.onmicrosoft.com" ` -CertThumbprint "AABBCCDDEEFF11223344556677889900" -To "recipient@example.com" -FromAddress "sender@example.com" ` -Subject "Manual Email" -EmailBody "Hello from Manual!" Uses the provided AppId, TenantId, and CertThumbprint directly (no vault) to obtain a token and send an email.