|
| 1 | +# GraphAppToolkit Module |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +The **GraphAppToolkit** module provides a set of functions and classes to quickly create, configure, and manage Azure AD (Entra) application registrations for various Microsoft 365 scenarios. It focuses on app-only authentication with certificates, storing credentials securely in SecretManagement vaults, and simplifying tasks like sending emails from a service principal, managing mail-enabled groups, and publishing specialized apps for M365 auditing or MEM policy management. |
| 6 | + |
| 7 | +## Help Documentation |
| 8 | + |
| 9 | +In addition to in-line PowerShell help (`Get-Help <FunctionName> -Full`), you can refer to the `about_GraphAppToolkit.help.txt` file (if included in the module) or any published documentation for more details on usage. |
| 10 | + |
| 11 | +## Public Functions |
| 12 | + |
| 13 | +The following Public Functions are exposed by the **GraphAppToolkit** module: |
| 14 | + |
| 15 | +- **New-MailEnabledSendingGroup** |
| 16 | + Creates a new mail-enabled security group in Exchange Online for restricted send scenarios. |
| 17 | + |
| 18 | +- **Publish-TkEmailApp** |
| 19 | + Publishes a Microsoft Graph Email App with certificate-based authentication and optionally restricts sending to a specific mail-enabled group. |
| 20 | + |
| 21 | +- **Publish-TkM365AuditApp** |
| 22 | + Publishes an Azure AD application with read-only or read-write sets of Graph/SharePoint/Exchange permissions for auditing or compliance tasks. |
| 23 | + |
| 24 | +- **Publish-TkMemPolicyManagerApp** |
| 25 | + Publishes an Azure AD application for MEM (Intune) policy management, supporting read-only or read-write permissions. |
| 26 | + |
| 27 | +- **Send-TkEmailAppMessage** |
| 28 | + Sends an email using a previously published email app’s certificate-based authentication (no user mailbox required). |
| 29 | + |
| 30 | +## Private Functions |
| 31 | + |
| 32 | +The following Private Functions support the module’s internal processes and are not exported: |
| 33 | + |
| 34 | +- **Connect-TkMsService** |
| 35 | +- **ConvertTo-ParameterSplat** |
| 36 | +- **Initialize-TkAppAuthCertificate** |
| 37 | +- **Initialize-TkAppSpRegistration** |
| 38 | +- **Initialize-TkModuleEnv** |
| 39 | +- **New-TkAppName** |
| 40 | +- **New-TkAppRegistration** |
| 41 | +- **New-TkExchangeEmailAppPolicy** |
| 42 | +- **New-TkRequiredResourcePermissionObject** |
| 43 | +- **Set-TkJsonSecret** |
| 44 | +- **Test-IsAdmin** |
| 45 | +- **Write-AuditLog** |
| 46 | + |
| 47 | +These private functions handle core logic like certificate generation, connecting to Microsoft services, app registration, secret storage, and logging. |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +## Examples |
| 52 | + |
| 53 | +### Example 1: Creating a Mail-Enabled Security Group |
| 54 | + |
| 55 | +```powershell |
| 56 | +$DefaultDomain = 'contoso.com' |
| 57 | +$MailEnabledSendingGroupToCreate = "CTSO-GraphAPIMail" |
| 58 | +# Creates a mail-enabled security group named "MySenders" using a default domain |
| 59 | +$group = New-MailEnabledSendingGroup -Name $MailEnabledSendingGroupToCreate -DefaultDomain $DefaultDomain |
| 60 | +``` |
| 61 | + |
| 62 | +### Example 2: Publishing a Graph Email App |
| 63 | + |
| 64 | +# Publishes an email app restricted to a mail-enabled group |
| 65 | + |
| 66 | +```powershell |
| 67 | +# Uses Group Variable from Example 1 |
| 68 | +$LicensedUserToSendAs = '[email protected]' |
| 69 | +$TwoToFourLetterCompanyAbbreviation = "CTSO" |
| 70 | +Publish-TkEmailApp ` |
| 71 | + -AppPrefix $TwoToFourLetterCompanyAbbreviation ` |
| 72 | + -AuthorizedSenderUserName $LicensedUserToSendAs ` |
| 73 | + -MailEnabledSendingGroup $group.PrimarySmtpAddress ` |
| 74 | + -ReturnParamSplat |
| 75 | +``` |
| 76 | + |
| 77 | +### Example 3: Sending Email from the Published App |
| 78 | + |
| 79 | +```powershell |
| 80 | +# Param Splat returned from Example 2 will have all values populated |
| 81 | +$params = @{ |
| 82 | + AppId = "your-app-id" |
| 83 | + Id = "your-app-object-id" |
| 84 | + AppName = "CN=YourAppName" |
| 85 | + AppRestrictedSendGroup = "[email protected]" |
| 86 | + CertExpires = "yyyy-MM-dd HH:mm:ss" |
| 87 | + CertThumbprint = "your-cert-thumbprint" |
| 88 | + ConsentUrl = "https://login.microsoftonline.com/your-tenant-id/adminconsent?client_id=your-app-id" |
| 89 | + DefaultDomain = 'contoso.com' |
| 90 | + SendAsUser = 'helpdesk' |
| 91 | + SendAsUserEmail = '[email protected]' |
| 92 | + TenantID = "your-tenant-id" |
| 93 | +} |
| 94 | +# Sends an email using a previously published TkEmailApp |
| 95 | +Send-TkEmailAppMessage ` |
| 96 | + -AppName $params.AppName ` |
| 97 | + |
| 98 | + -FromAddress $params.SendAsUserEmail ` |
| 99 | + -Subject 'Test Email' ` |
| 100 | + -EmailBody 'This is a test email.' ` |
| 101 | + -AttachmentPath 'C:\temp\attachmentFile.zip', 'C:\temp\anotherAttachmentFile.zip' ` |
| 102 | + -ReturnParamSplat |
| 103 | +
|
| 104 | +# Send using manual parameters |
| 105 | +$AppId = "00000000-1111-2222-3333-444444444444" |
| 106 | +$TenantId = "00000000-1111-2222-3333-444444444444" |
| 107 | +$CertThumbprint = "AABBCCDDEEFF11223344556677889900" |
| 108 | + |
| 109 | +$FromAddress = '[email protected]' |
| 110 | +Send-TkEmailAppMessage ` |
| 111 | + -AppId $AppId ` |
| 112 | + -TenantId $TenantId ` |
| 113 | + -CertThumbprint $CertThumbprint ` |
| 114 | + -To $To ` |
| 115 | + -FromAddress $FromAddress ` |
| 116 | + -Subject "Manual Email" ` |
| 117 | + -EmailBody "Hello from Manual!" |
| 118 | +``` |
| 119 | + |
| 120 | +### Example 4: Publishing an M365 Audit App |
| 121 | + |
| 122 | +```powershell |
| 123 | +# Publishes a read-only M365 audit app (e.g., for directory or device management auditing) |
| 124 | +Publish-TkM365AuditApp -AppPrefix "CSN" -CertThumbprint "FACEBEEFBEEFAABBCCDDEEFF11223344" |
| 125 | +``` |
| 126 | + |
| 127 | +### Example 5: Publishing a MEM Policy Manager App |
| 128 | + |
| 129 | +```powershell |
| 130 | +# Publishes a read-write MEM Policy Manager app with a self-signed cert |
| 131 | +Publish-TkMemPolicyManagerApp -AppPrefix "MEM" -ReadWrite |
| 132 | +``` |
0 commit comments