Scheduling Azure RM Automation Schedule

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: (:slight_smile: [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.

Does the account you are using have service principal authentication rights?

see this similar issue https://github.com/Azure/azure-powershell/issues/1309

The weird thing is that I can see the account I specify login. I’ve been able to use other cmdlets in Azure. Just not the three for scheduling a job.

I’ll try some of the ideas in the thread … Thank you for your post.

So I’ve attempted the Service Principal and I stil cannot seem to get it to work.

See this thread:
https://github.com/Azure/azure-powershell/issues/2179

Ok at the end of the day my issue stemmed from not having all the modules updated and close to the same version.

Note to self make sure you update modules 1st.