Update:
It seems that someone had the same problem and reported it.
I am facing the problem of a simple PowerShell script when calling it from Runbook Automation Runbook. The same piece of code works flawlessly when used locally .
I added the Service Principle to Azure Active Directory (hosted on the Azure German Cloud) with password credentials and provided it with a subscription access contributor (also hosted on the Azure German Cloud).
Azure Automation is hosted in Northern Europe because it is currently not available on Azure German Cloud.
All I'm trying to do is log in to my subscription with the aforementioned director using the Add-AzureRmAccount . After that, I try to set the current context using Set-AzureRmContext and get the following error message:
Set-AzureRmContext : Please provide a valid tenant or a valid subscription. At line:26 char:1 + Set-AzureRmContext -TenantId $TenantId -Su ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Set-AzureRmContext], ArgumentException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Profile.SetAzureRMContextCommand
Here is the script I'm trying to run (left an empty configuration):
$TenantId = "" $ApplicationId = "" $ClientSecret = "" $SubscriptionId = "" $secpasswd = ConvertTo-SecureString $ClientSecret -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ($ApplicationId , $secpasswd) Add-AzureRmAccount -ServicePrincipal -Environment 'AzureGermanCloud' -Credential $mycreds -TenantId $TenantId Set-AzureRmContext -TenantId $TenantId -SubscriptionId $SubscriptionId
I also tried using Login-AzureRmAccount without success. I can also use the Get-AzureRmResourceGroup to retrieve resource groups, so the login seems to work.
All Azure Modules have been updated to the latest version.
translator:
My main goal is to run the SQL export job using New-AzureRmSqlDatabaseExport from the workbook, but it seems that the above error causes the cmdlet to fail with the message:
New-AzureRmSqlDatabaseExport : Your Azure credentials have not been set up or have expired, please run Login-AzureRMAccount to set up your Azure credentials. At line:77 char:18 + ... rtRequest = New-AzureRmSqlDatabaseExport -ResourceGroupName $Resource