New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't schedule a Job via Azure automation (get-AzureRmAutomationSchedule,new-azurermAutomationschedule, register-AzureRmAutomationScheduledRunbook) #2179
Comments
Is this what I need to do to allow for scheduling jobs? |
@crshnbrn66 Using ServicePrincipal is suggested for automating azure activities in powershell (or any of the Azure SDKs). User authentication will work using PSCredential, but only for OrgID accounts, and only if multi-factor authentication is not turned on for those logins. Note that there is a much simpler script for setting up service principal certificate authenticatiuon here: https://azure.microsoft.com/en-us/blog/azps-1-0/ in the 'Certficiate Authentication with Azure Resource Manager' section. The articale above will work, however, the MSOL cmdlets are generally not needed. How is this script executed? Generally, your azure login is tied to the current AppDomain, unless you use Save-AzureRMProfile to save it to dis and Select-AzureRMProfile to reload it. If the cmdlets run in a different AppDomain than the login, this could be the issue. |
Awesome thank you for the feed back Mark. |
One comment... this command doesn't seem to work but on Windows 10: Because of the KeyExportPolicy param and -NotAfter param switches. I had to use Makecert. :) |
@crshnbrn66 Thanks, can you leave that comment on the blog post - we can add some extra notes about downlevel OS's (and how to acquire MakeCert). Will leave this open, as that blog post is due to be updated. |
I updated the code for it and created a pull request. One other question I've now created the connection and followed the instructions in this post: I'm still getting errors when I attempt to get-automationscheduling information
Error: ERROR: Get-AzureRmAutomationSchedule : Run Login-AzureRmAccount to login.
|
Here is the updated pull request I did for the Service Principal script |
I'm able to Query other cmdlets using the Service principal setup... However when I try and get an automation schedule or the others identified in this issue I get the same login error. |
@crshnbrn66 This looks more like an issue specific to those cmdlets. @jodoglevy Any insight into why these three cmdlets might be different than others? |
@crshnbrn66 If you run the cmdlets with |
@crshnbrn66 what module versions do you have in your automation account? What does get-module -listavailable return in a runbook? |
running this: Results: |
Can you run just the get module line and see what comes out?
|
Only thing I ran was: get-module -ListAvailable Suspended I ran from the original run book and then from a new run book and both times it tried to run it three times to list out the modules and gave me the error above. Directory: C:\Program Files\WindowsPowerShell\Modules Binary 1.0.0.0 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packag... ModuleType Version Name ExportedCommands Manifest 1.0.0.0 CimCmdlets {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance, ... ModuleType Version Name ExportedCommands Manifest 1.0.6 AzureRM.Insights {Add-AzureRmMetricAlertRule, Add-AzureRmLogAlertRule, Add-A...
ModuleType Version Name ExportedCommands Binary 1.0.0.0 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packag... ModuleType Version Name ExportedCommands Manifest 1.0.0.0 CimCmdlets {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance, ... ModuleType Version Name ExportedCommands Manifest 1.0.6 AzureRM.Insights {Add-AzureRmMetricAlertRule, Add-AzureRmLogAlertRule, Add-A...
ModuleType Version Name ExportedCommands Binary 1.0.0.0 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packag... ModuleType Version Name ExportedCommands Manifest 1.0.0.0 CimCmdlets {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance, ... ModuleType Version Name ExportedCommands Manifest 1.0.6 AzureRM.Insights {Add-AzureRmMetricAlertRule, Add-AzureRmLogAlertRule, Add-A... |
According to that list you only have the Azure Insights and Profile modules in your account...are you sure that's the whole list? |
Ok this morning this ran and didn't time out here is an update: get-module -ListAvailable
ModuleType Version Name ExportedCommands Binary 1.0.0.0 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packag... Script 1.0 PowerShellGet {Install-Module, Find-Module, Save-Module, Update-Module...}
ModuleType Version Name ExportedCommands Manifest 1.0.0.0 CimCmdlets {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance, ... Script 1.0.0.0 ISE {New-IseSnippet, Import-IseSnippet, Get-IseSnippet} Manifest 1.0.0.0 Microsoft.PowerShell.Archive {Compress-Archive, Expand-Archive} Manifest 3.0.0.0 Microsoft.PowerShell.Diagnostics {Get-WinEvent, Get-Counter, Import-Counter, Export-Counter...} Manifest 3.0.0.0 Microsoft.PowerShell.Host {Start-Transcript, Stop-Transcript} Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...} Script 1.0 Microsoft.PowerShell.ODataUtils Export-ODataEndpointProxy Manifest 3.0.0.0 Microsoft.PowerShell.Security {Get-Acl, Set-Acl, Get-PfxCertificate, Get-Credential...} Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Format-List, Format-Custom, Format-Table, Format-Wide...} Manifest 3.0.0.0 Microsoft.WSMan.Management {Disable-WSManCredSSP, Enable-WSManCredSSP, Get-WSManCredSS... Manifest 1.0.0.0 NetworkSwitchManager {Disable-NetworkSwitchEthernetPort, Enable-NetworkSwitchEth... Manifest 1.1 PSDesiredStateConfiguration {Set-DscLocalConfigurationManager, Start-DscConfiguration, ... Script 1.0.0.0 PSDiagnostics {Disable-PSTrace, Disable-PSWSManCombinedTrace, Disable-WSM... Binary 1.1.0.0 PSScheduledJob {New-JobTrigger, Add-JobTrigger, Remove-JobTrigger, Get-Job... Manifest 2.0.0.0 PSWorkflow {New-PSWorkflowExecutionOption, New-PSWorkflowSession, nwsn} Manifest 1.0.0.0 PSWorkflowUtility Invoke-AsWorkflow Manifest 2.0.0.0 SoftwareInventoryLogging {Get-SilComputer, Get-SilComputerIdentity, Get-SilSoftware,...
ModuleType Version Name ExportedCommands Manifest 1.0.6 AzureRM.Insights {Add-AzureRmMetricAlertRule, Add-AzureRmLogAlertRule, Add-A... Manifest 1.0.6 AzureRM.profile {Enable-AzureRmDataCollection, Disable-AzureRmDataCollectio...
ModuleType Version Name ExportedCommands Binary 1.0.0.0 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packag... Script 1.0 PowerShellGet {Install-Module, Find-Module, Save-Module, Update-Module...}
ModuleType Version Name ExportedCommands Manifest 1.0.0.0 CimCmdlets {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance, ... Script 1.0.0.0 ISE {New-IseSnippet, Import-IseSnippet, Get-IseSnippet} Manifest 1.0.0.0 Microsoft.PowerShell.Archive {Compress-Archive, Expand-Archive} Manifest 3.0.0.0 Microsoft.PowerShell.Diagnostics {Get-WinEvent, Get-Counter, Import-Counter, Export-Counter...} Manifest 3.0.0.0 Microsoft.PowerShell.Host {Start-Transcript, Stop-Transcript} Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...} Script 1.0 Microsoft.PowerShell.ODataUtils Export-ODataEndpointProxy Manifest 3.0.0.0 Microsoft.PowerShell.Security {Get-Acl, Set-Acl, Get-PfxCertificate, Get-Credential...} Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Format-List, Format-Custom, Format-Table, Format-Wide...} Manifest 3.0.0.0 Microsoft.WSMan.Management {Disable-WSManCredSSP, Enable-WSManCredSSP, Get-WSManCredSS... Manifest 1.0.0.0 NetworkSwitchManager {Disable-NetworkSwitchEthernetPort, Enable-NetworkSwitchEth... Manifest 1.1 PSDesiredStateConfiguration {Set-DscLocalConfigurationManager, Start-DscConfiguration, ... Script 1.0.0.0 PSDiagnostics {Disable-PSTrace, Disable-PSWSManCombinedTrace, Disable-WSM... Binary 1.1.0.0 PSScheduledJob {New-JobTrigger, Add-JobTrigger, Remove-JobTrigger, Get-Job... Manifest 2.0.0.0 PSWorkflow {New-PSWorkflowExecutionOption, New-PSWorkflowSession, nwsn} Manifest 1.0.0.0 PSWorkflowUtility Invoke-AsWorkflow Manifest 2.0.0.0 SoftwareInventoryLogging {Get-SilComputer, Get-SilComputerIdentity, Get-SilSoftware,...
ModuleType Version Name ExportedCommands Manifest 1.0.6 AzureRM.Insights {Add-AzureRmMetricAlertRule, Add-AzureRmLogAlertRule, Add-A... Manifest 1.0.6 AzureRM.profile {Enable-AzureRmDataCollection, Disable-AzureRmDataCollectio...
ModuleType Version Name ExportedCommands Binary 1.0.0.0 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packag... Script 1.0 PowerShellGet {Install-Module, Find-Module, Save-Module, Update-Module...}
ModuleType Version Name ExportedCommands Manifest 1.0.0.0 CimCmdlets {Get-CimAssociatedInstance, Get-CimClass, Get-CimInstance, ... Script 1.0.0.0 ISE {New-IseSnippet, Import-IseSnippet, Get-IseSnippet} Manifest 1.0.0.0 Microsoft.PowerShell.Archive {Compress-Archive, Expand-Archive} Manifest 3.0.0.0 Microsoft.PowerShell.Diagnostics {Get-WinEvent, Get-Counter, Import-Counter, Export-Counter...} Manifest 3.0.0.0 Microsoft.PowerShell.Host {Start-Transcript, Stop-Transcript} Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Content, Clear-Content, Clear-ItemProperty, Join-Path...} Script 1.0 Microsoft.PowerShell.ODataUtils Export-ODataEndpointProxy Manifest 3.0.0.0 Microsoft.PowerShell.Security {Get-Acl, Set-Acl, Get-PfxCertificate, Get-Credential...} Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Format-List, Format-Custom, Format-Table, Format-Wide...} Manifest 3.0.0.0 Microsoft.WSMan.Management {Disable-WSManCredSSP, Enable-WSManCredSSP, Get-WSManCredSS... Manifest 1.0.0.0 NetworkSwitchManager {Disable-NetworkSwitchEthernetPort, Enable-NetworkSwitchEth... Manifest 1.1 PSDesiredStateConfiguration {Set-DscLocalConfigurationManager, Start-DscConfiguration, ... Script 1.0.0.0 PSDiagnostics {Disable-PSTrace, Disable-PSWSManCombinedTrace, Disable-WSM... Binary 1.1.0.0 PSScheduledJob {New-JobTrigger, Add-JobTrigger, Remove-JobTrigger, Get-Job... Manifest 2.0.0.0 PSWorkflow {New-PSWorkflowExecutionOption, New-PSWorkflowSession, nwsn} Manifest 1.0.0.0 PSWorkflowUtility Invoke-AsWorkflow Manifest 2.0.0.0 SoftwareInventoryLogging {Get-SilComputer, Get-SilComputerIdentity, Get-SilSoftware,...
ModuleType Version Name ExportedCommands Manifest 1.0.6 AzureRM.Insights {Add-AzureRmMetricAlertRule, Add-AzureRmLogAlertRule, Add-A... Manifest 1.0.6 AzureRM.profile {Enable-AzureRmDataCollection, Disable-AzureRmDataCollectio... |
I still only see the Azure insights and profile modules. If you go in to your automation account to Assets -> Modules -> what Azure/AzureRM modules show up, and what is the version listed for each? |
Azure 1.0.3 I see what you are getting / driving at I'll make some updates. |
Yes looks like your Azure/AzureRM modules are not of the same version. AzureRM PowerShell modules can run into issues if they are using mismatched versions. Try updating all your Azure/AzureRM modules to the latest version. |
Joe thank you very much for your time and insight. |
For what its worth. I could have saved myself 5 days if I'd have updated the modules first. |
I have a Azure automation script that I'm using to schedule Azure jobs.
Also Written up here: http://powershell.org/wp/forums/topic/scheduling-azure-rm-automation-schedule/
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 in turn logs in as the user specified. then attempts to run anyone of the following cmdlets (get-AzureRmAutomationSchedule,new-azurermAutomationschedule, register-AzureRmAutomationScheduledRunbook )
I get:
Get-AzureRmAutomationSchedule : Run Login-AzureRmAccount to login.
At line:54 char:16
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
If anyone can think of or offer advice on what I need to do or something I've forgotten I'm all ears.
The text was updated successfully, but these errors were encountered: