Skip to content

Commit 98854ee

Browse files
committed
removed: Module install in mail app when using manual params
1 parent 103f7ad commit 98854ee

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020

2121
- Updated private function names to be more descriptive.
2222
- Removed MSAL.PS dependency from Send-TkEmailAppMessage function.
23+
- Removed Send-TkEmailAppMessage module install if manual parameters are provided.
2324

2425
## [0.2.0] - 2025-03-14
2526

source/Public/Send-TkEmailAppMessage.ps1

+12-12
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,6 @@ function Send-TkEmailAppMessage {
183183
Write-AuditLog -BeginFunction
184184
}
185185
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
197186
# If manual parameter set:
198187
if ($PSCmdlet.ParameterSetName -eq 'Manual') {
199188
$cert = Get-ChildItem -Path Cert:\CurrentUser\My | Where-Object { $_.Thumbprint -eq $CertThumbprint } -ErrorAction Stop
@@ -207,6 +196,17 @@ function Send-TkEmailAppMessage {
207196
$Tenant = $TenantId
208197
}
209198
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
210210
# If a GraphEmailApp object was not passed in, attempt to retrieve it from the local machine
211211
if ($AppName) {
212212
try {
@@ -242,7 +242,7 @@ function Send-TkEmailAppMessage {
242242
Process {
243243
# https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-client-creds-grant-flow#second-case-access-token-request-with-a-certificate
244244
# 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 `
246246
-ClientCertificate $Cert `
247247
-ClientId $AppId `
248248
-TenantId $Tenant `

0 commit comments

Comments
 (0)