@@ -183,17 +183,6 @@ function Send-TkEmailAppMessage {
183
183
Write-AuditLog - BeginFunction
184
184
}
185
185
Write-AuditLog ' ###########################################################'
186
- # Install and import the Microsoft.Graph module. Tested: 1.22.0
187
- $PublicMods = `
188
- ' Microsoft.PowerShell.SecretManagement' , ' SecretManagement.JustinGrote.CredMan'
189
- $PublicVers = `
190
- ' 1.1.2' , ' 1.0.0' , ' 4.37.0.0'
191
- $params1 = @ {
192
- PublicModuleNames = $PublicMods
193
- PublicRequiredVersions = $PublicVers
194
- Scope = ' CurrentUser'
195
- }
196
- Initialize-TkModuleEnv @params1
197
186
# If manual parameter set:
198
187
if ($PSCmdlet.ParameterSetName -eq ' Manual' ) {
199
188
$cert = Get-ChildItem - Path Cert:\CurrentUser\My | Where-Object { $_.Thumbprint -eq $CertThumbprint } - ErrorAction Stop
@@ -207,6 +196,17 @@ function Send-TkEmailAppMessage {
207
196
$Tenant = $TenantId
208
197
}
209
198
elseif ($PSCmdlet.ParameterSetName -eq ' Vault' ) {
199
+ # Install and import the Microsoft.Graph module. Tested: 1.22.0
200
+ $PublicMods = `
201
+ ' Microsoft.PowerShell.SecretManagement' , ' SecretManagement.JustinGrote.CredMan'
202
+ $PublicVers = `
203
+ ' 1.1.2' , ' 1.0.0' , ' 4.37.0.0'
204
+ $params1 = @ {
205
+ PublicModuleNames = $PublicMods
206
+ PublicRequiredVersions = $PublicVers
207
+ Scope = ' CurrentUser'
208
+ }
209
+ Initialize-TkModuleEnv @params1
210
210
# If a GraphEmailApp object was not passed in, attempt to retrieve it from the local machine
211
211
if ($AppName ) {
212
212
try {
@@ -242,7 +242,7 @@ function Send-TkEmailAppMessage {
242
242
Process {
243
243
# https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-client-creds-grant-flow#second-case-access-token-request-with-a-certificate
244
244
# Authenticate with Azure AD and obtain an access token for the Microsoft Graph API using the certificate
245
- $MSToken = Get-TkMsalToken `
245
+ $MSToken = Get-TkMsalToken `
246
246
- ClientCertificate $Cert `
247
247
- ClientId $AppId `
248
248
- TenantId $Tenant `
0 commit comments