Azure / Azure/azure-functions-templates
PowerShell Modules not loaded correctly
- Dominant language
- C#
- Stars
- 363
- Forks
- 206
- Avg merge
- 15m
- Merged PRs (30d)
- 1
Description
Hi guys
As described in this post [here](https://social.msdn.microsoft.com/Forums/en-US/ae8138ba-508d-47ef-bf72-c327de01c065/azure-functions-any-changes-updates-on-azure-function-servers-occured-last-night-#2ab469c2-c927-4b7e-adf0-2842f9c252cc), I encountered a problem when importing new PowerShell modules from a path in an Azure powershell (experimental language) function. Everything looks fine, modules seems to be loaded correctly, but when I am doing
``` PowerShell
$secretRetrieved = Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name $certName
Get-AzureKeyVaultSecret : Run Connect-AzureRmAccount to login.
```
I get an exception saying
> Get-AzureKeyVaultSecret : Run Connect-AzureRmAccount to login.
The problem is that I am already running this command few lines before the Get-AzureKeyVaultSecret.
So if I remove my Import-module commands, it will get version 1.x already installed on Azure function environment and everything is working fine even the Get-AzureKeyVaultSecret. If I want to import my PowerShell modules, then the import is done correctly but the command failed.
``` PowerShell
$env:AppId = "my-app-id"
$env:AppSecret = "my-app-secret"
$env:TenantId = "my-tenant-id"
$environmentPrefix = "dev"
$secureAppPwd = ConvertTo-SecureString $env:AppSecret -AsPlainText -Force
$appCred = New-Object System.Management.Automation.PSCredential ($env:AppId, $secureAppPwd)
Login-AzureRmAccount -ServicePrincipal -Credential $appCred -TenantId $env:TenantId
$keyVaultName = "$environmentPrefix-my-keyvault-name"
$certName = "my-certificate-name"
$secretRetrieved = Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name $certName
# Display my secret
$secretRetrieved
# Display loaded modules
Get-Module
```
You can find the entire description in the post.
Contributor guide
No contributing guide indexed for this repository
Research direction
No repository file or test is named. Start by reproducing the Azure Functions PowerShell scenario with the custom Import-Module commands, Login-AzureRmAccount, and Get-AzureKeyVaultSecret, then inspect Get-Module and the loaded module versions. Done means the imported modules load without replacing or losing the authenticated session, and the Key Vault command succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, powershell
- Domain
- authentication, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100