Can you try using Browse Gallery option to install the module, this way it will give you more information when it's failed.
Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
When I am trying to add a module by using the Azure portal, it shows approximately 32 dependencies that need to be added first, but after that, it also gives the same result. For the above image, I have used Azure CLI.
$moduleName = <ModuleName>
$moduleVersion = <ModuleVersion>
New-AzAutomationModule -AutomationAccountName <AutomationAccountName> -ResourceGroupName <ResourceGroupName> -Name $moduleName -ContentLinkUri "https://www.powershellgallery.com/api/v2/package/$moduleName/$moduleVersion"
The output was positive, but it failed to import the module without giving any error.
# Import the necessary modules
Import-Module Az.Accounts
Import-Module Az.Resources
Import-Module Az.Automation
Import-Module Microsoft.Graph
# Replace with your actual values
$subscriptionId = "<Your Subscription ID>"
$resourceGroupName = "<Your Resource Group Name>"
$automationAccountName = "<Your Automation Account Name>"
$appIds = @("-", "-")
$userId = "-"
$managedIdentityObjectId = "<Your Managed Identity Object ID>"
# Connect to Azure using the system managed identity of the automation account
Connect-AzAccount -Identity
# Retrieve secrets' expiration dates from Azure AD App credentials
$secretsExpiration = @()
foreach ($appId in $appIds) {
$appSecrets = Get-AzADAppCredential -ApplicationId $appId
if ($appSecrets -ne $null) {
$secretsExpiration += @{
AppId = $appId
ExpirationDate = $appSecrets.EndDate
}
}
}
# Format secrets' expiration dates
$expirationDatesString = $secretsExpiration | ForEach-Object {
"AppId: $($_.AppId)`r`nExpiration Date: $($_.ExpirationDate)`r`n"
} | Out-String
# Prepare email content
$emailContent = @{
subject = "Secret Expiration Reminder from Azure Automation"
body = @{
contentType = "Text"
content = @"
Hi Team,
Here are the expiration dates of the secrets for the App Registrations:
$expirationDatesString
Please update the secrets before they expire.
Best regards,
Jatin
"@
}
toRecipients = @(@{emailAddress = @{address = $userId}})
}
# Convert the email content to JSON
$jsonContent = $emailContent | ConvertTo-Json
# Acquire access token using Managed Identity
$graphApiToken = Get-AzAccessToken -ResourceUrl "https://graph.microsoft.com" -ObjectId $managedIdentityObjectId
# Construct the REST API URL
$apiUrl = "https://graph.microsoft.com/v1.0/me/sendMail"
# Send the email using the Outlook REST API
$response = Invoke-RestMethod -Uri $apiUrl -Method Post -Headers @{
Authorization = "Bearer $($graphApiToken.Token)"
"Content-Type" = "application/json"
} -Body $jsonContent
# Check the response status
if ($response.StatusCode -eq 202) {
Write-Output "Email sent successfully."
} else {
Write-Output "Failed to send email."
Write-Output "Response: $($response | ConvertTo-Json -Depth 4)"
}
This script is to get notified of expired app secrets. Please let me know what can be done to address this issue.
Can you try using Browse Gallery option to install the module, this way it will give you more information when it's failed.
Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.