I have a Azure automation script that I’m using to schedule azure jobs.
when I run the script under my own credentials and session it works fine.
When I attempt to use this with a webhook that calls script that then inturn logs in as the user specified. then attempts to run anyone of the following cmdlets (et-AzureRmAutomationSchedule,new-azurermAutomationschedule, register-AzureRmAutomationScheduledRunbook ) I get:
Get-AzureRmAutomationSchedule : Run Login-AzureRmAccount to login.
At line:54 char:16
- … if(Get-AzureRmAutomationSchedule -name $jobname -ResourceGro …
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: ( [Get-AzureRmAutomationSchedule], PSInvalidOperationException
- FullyQualifiedErrorId : InvalidOperation,Microsoft.Azure.Commands.Automation.Cmdlet.GetAzureAutomationSchedule
I’ve mocked up one of the calls and use it in a Azure job and i get the same result code follows:
Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string]$credential ) $cred = Get-AutomationPSCredential -Name $credential Add-AzureRmAccount -Credential $cred set-azurermcontext -subscriptionName 'Azure Testing' Get-AzureRmAutomationSchedule -name CaptureAlerts-MemoryPercentage -ResourceGroupName AzureTesting -AutomationAccountName AutomationAccountTest -Verbose -ErrorAction SilentlyContinue
Error:
Account Environment Subscription Tenant
xxx@ok.com AzureCloud xzzzddd
ERROR: Get-AzureRmAutomationSchedule : Run Login-AzureRmAccount to login.
At line:10 char:1
- Get-AzureRmAutomationSchedule -name CaptureAlerts-MemoryPercentage -R …
-
+ CategoryInfo : InvalidOperation: (:) [Get-AzureRmAutomationSchedule], PSInvalidOperationException + FullyQualifiedErrorId : InvalidOperation,Microsoft.Azure.Commands.Automation.Cmdlet.GetAzureAutomationSchedule
If anyone can think of or offer advice on what I need to do or something I’ve forgotten I’m all ears.