diff --git a/PSF.psd1 b/PSF.psd1 index eba8631..c1c4161 100644 --- a/PSF.psd1 +++ b/PSF.psd1 @@ -69,7 +69,7 @@ Description = 'PowerShell Functions Module' # NestedModules = @() # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = @('Get-oAuthToken', 'Get-RandomPassword') +FunctionsToExport = @('Get-oAuthToken', 'Get-RandomPassword', 'Connect-AadWithRmContext') # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @() diff --git a/PSF.psm1 b/PSF.psm1 index e2120f1..e0df1d3 100644 --- a/PSF.psm1 +++ b/PSF.psm1 @@ -2,3 +2,4 @@ . $PSScriptRoot\functions\Get-oAuthToken.ps1 . $PSScriptRoot\functions\Get-RandomPassword.ps1 +. $PSScriptRoot\functions\Connect-AadWithRmContext.ps1 diff --git a/appveyor.yml b/appveyor.yml index 0a809b6..ffac007 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,8 +4,10 @@ environment: secure: v711B0A/aGDr4wVCW3sYtaJJljC+rXipS2PENvcBC+qtOs4VXS9QWDTMJyQIKLTv install: - - choco install gitversion.portable -pre -y - - rm C:\Tools\GitVersion\GitVersion.exe + - gitversion /version + # - choco install gitversion.portable -y + # - rm C:\Tools\GitVersion\GitVersion.exe + # - gitversion /version - ps: Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force before_build: diff --git a/functions/Connect-AadWithRmContext.ps1 b/functions/Connect-AadWithRmContext.ps1 new file mode 100644 index 0000000..afb5829 --- /dev/null +++ b/functions/Connect-AadWithRmContext.ps1 @@ -0,0 +1,26 @@ +function Connect-AadWithRmContext { + <# + .SYNOPSIS + Connect to Azure AD using an existing Azure RM Context. + .DESCRIPTION + This Function connects to the Microsoft AAD using an existing Azure RM context by + leveraging the exiting oAuth token for Azure RM. + .EXAMPLE + Connect-AadWithRmContext + .NOTES + Version 1.0.1 + #> + + $Context = Get-AzureRmContext + # Force context to grab a token for GraphAPI + Get-AzureRmADUser -UserPrincipalName $Context.Account.Id + + $CacheItems = $Context.TokenCache.ReadItems() + + $Token = ($CacheItems | Where-Object { $_.Resource -eq "https://graph.windows.net/" -and $_.TenantId -eq $Context.Tenant.Id }) + if ($Token.ExpiresOn -le [System.DateTime]::UtcNow) { + $AC = [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]::new("$($Context.Environment.ActiveDirectoryAuthority)$($Context.Tenant.Id)", $Token) + $Token = $AC.AcquireTokenByRefreshToken($Token.RefreshToken, "1950a258-227b-4e31-a9cf-717495945fc2", "https://graph.windows.net") + } + Connect-AzureAD -AadAccessToken $Token.AccessToken -AccountId $Context.Account.Id -TenantId $Context.Tenant.Id | Out-Null +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy