Azure / Azure/azure-powershell
Error when exporting runbooks with an underscore "_"
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 3d 14h
- Merged PRs (30d)
- 54
Description
### Description
Azure allows me to create runbooks with an "_" (underscore) in the name, but when I try to export them with PowerShell I get an error
`Export-AzAutomationRunbook : 'runbookName' does not match expected pattern '^[a-zA-Z]*-*[a-zA-Z0-9]*$'.`
### Issue script & Debug output
```PowerShell
PS C:\Users\xxxxxx> $DebugPreference='Continue'
PS C:\Users\xxxxxx> Export-AzAutomationRunbook -ResourceGroupName "ResourceGroup" -AutomationAccountName "UserManagementTasks" -Name "C_Create" -Slot "Published" -OutputFolder "C:\temp\export"
DEBUG: 12:06:25 PM - ExportAzureAutomationRunbook begin processing with ParameterSet 'ByRunbookName'.
DEBUG: 12:06:25 PM - using account id 'xxxxxxyyyyyy'...
DEBUG: 12:06:25 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = [].
Returning default value [True].
DEBUG: [Common.Authentication]: Authenticating using Account: 'xxxxxxyyyyyy', environment: 'AzureCloud',
tenant: 'cxxxxxxxxxxxxxxxxxxxxxx2a'
DEBUG: 12:06:25 PM - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync -
TenantId:'c8xxxxxxxxxxxxxxxxxa', Scopes:'https://management.core.windows.net//.default',
AuthorityHost:'https://login.microsoftonline.com/', UserId:'xxxxxxyyyyyy'
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ]
ParentRequestId:
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
09dc220d-178f-45b2-882a-1094cf77f651] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
09dc220d-178f-45b2-882a-1094cf77f651] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
09dc220d-178f-45b2-882a-1094cf77f651] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
09dc220d-178f-45b2-882a-1094cf77f651] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
09dc220d-178f-45b2-882a-1094cf77f651] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
09dc220d-178f-45b2-882a-1094cf77f651] IsLegacyAdalCacheEnabled: yes
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z] [WamBroker] WAM
supported OS.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z] [WamBroker]
ListWindowsWorkAndSchoolAccounts option was not enabled.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
12f19f08-a130-43c9-bac1-6814295a8466] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z] Found 2 cache
accounts and 0 broker accounts
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z] Returning 2 accounts
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
db0baf62-9cce-4f8d-9bd0-521cf66ea781] MSAL MSAL.Desktop with assembly version '4.49.1.0'.
CorrelationId(db0baf62-9cce-4f8d-9bd0-521cf66ea781)
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
db0baf62-9cce-4f8d-9bd0-521cf66ea781] === AcquireTokenSilent Parameters ===
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
db0baf62-9cce-4f8d-9bd0-521cf66ea781] LoginHint provided: False
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
db0baf62-9cce-4f8d-9bd0-521cf66ea781] Account provided: True
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
db0baf62-9cce-4f8d-9bd0-521cf66ea781] ForceRefresh: False
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
db0baf62-9cce-4f8d-9bd0-521cf66ea781]
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.windows.net//.default
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - True
HomeAccountId - False
CorrelationId - db0baf62-9cce-4f8d-9bd0-521cf66ea781
UserAssertion set: False
LongRunningOboCacheKey set: False
Region configured:
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
db0baf62-9cce-4f8d-9bd0-521cf66ea781] === Token Acquisition (SilentRequest) started:
Scopes: https://management.core.windows.net//.default
Authority Host: login.microsoftonline.com
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
db0baf62-9cce-4f8d-9bd0-521cf66ea781] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
db0baf62-9cce-4f8d-9bd0-521cf66ea781] Access token is not expired. Returning the found cache entry. [Current time
(09/19/2023 16:06:25) - Expiration Time (09/19/2023 16:44:32 +00:00) - Extended Expiration Time (09/19/2023 16:44:32
+00:00)]
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
db0baf62-9cce-4f8d-9bd0-521cf66ea781] Returning access token found in cache. RefreshOn exists ? False
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
db0baf62-9cce-4f8d-9bd0-521cf66ea781] [Region discovery] Not using a regional authority.
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
db0baf62-9cce-4f8d-9bd0-521cf66ea781]
=== Token Acquisition finished successfully:
DEBUG: False MSAL 4.49.1.0 MSAL.Desktop 4.8 or later Windows 10 Enterprise [2023-09-19 16:06:25Z -
db0baf62-9cce-4f8d-9bd0-521cf66ea781] AT expiration time: 9/19/2023 4:44:32 PM +00:00, scopes:
https://management.core.windows.net//user_impersonation https://management.core.windows.net//.default. source: Cache
DEBUG: SharedTokenCacheCredential.GetToken succeeded. Scopes: [ https://management.core.windows.net//.default ]
ParentRequestId: ExpiresOn: 2023-09-19T16:44:32.0000000+00:00
DEBUG: [Common.Authentication]: Received token with LoginType 'User', Tenant: 'c8f302ba-b2fe-4389-b720-e285f4fe1b2a',
UserId: 'xxxxxxyyyyyy'
DEBUG: 12:06:25 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning
default value [True].
Export-AzAutomationRunbook : 'runbookName' does not match expected pattern '^[a-zA-Z]*-*[a-zA-Z0-9]*$'.
At line:1 char:1
+ Export-AzAutomationRunbook -ResourceGroupName "ResourceGroup" -Autom ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Export-AzAutomationRunbook], ValidationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Automation.Cmdlet.ExportAzureAutomationRunbook
DEBUG: 12:06:25 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = [].
Returning default value [True].
DEBUG: AzureQoSEvent: Module: Az.Automation:1.9.0; CommandName: Export-AzAutomationRunbook; PSVersion: 5.1.22621.1778;
IsSuccess: False; Duration: 00:00:00.0914826; Exception: 'runbookName' does not match expected pattern
'^[a-zA-Z]*-*[a-zA-Z0-9]*$'.;
DEBUG: 12:06:25 PM - ExportAzureAutomationRunbook end processing.
```
### Environment data
```PowerShell
Name Value
---- -----
PSVersion 5.1.22621.1778
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22621.1778
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
```
### Module versions
```PowerShell
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 2.11.1 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear...
Script 1.9.0 Az.Automation {Export-AzAutomationDscConfiguration, Export-AzAutomationD...
```
### Error output
```PowerShell
Message : 'runbookName' does not match expected pattern '^[a-zA-Z]*-*[a-zA-Z0-9]*$'.
StackTrace : at
Microsoft.Azure.Management.Automation.RunbookOperations.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Management.Automation.RunbookOperationsExtensions.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Management.Automation.RunbookOperationsExtensions.Get(IRunbookOperations
operations, String resourceGroupName, String automationAccountName, String runbookName)
at Microsoft.Azure.Commands.Automation.Common.AutomationPSClient.TryGetRunbookModel(String
resourceGroupName, String automationAccountName, String runbookName)
at Microsoft.Azure.Commands.Automation.Common.AutomationPSClient.ExportRunbook(String
resourceGroupName, String automationAccountName, String runbookName, Nullable`1 isDraft, String
outputFolder, Boolean overwrite)
at
Microsoft.Azure.Commands.Automation.Cmdlet.ExportAzureAutomationRunbook.AutomationProcessRecord()
at Microsoft.Azure.Commands.Automation.Cmdlet.AzureAutomationBaseCmdlet.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception : Microsoft.Rest.ValidationException
InvocationInfo : {Export-AzAutomationRunbook}
Line : foreach($b in $runbooks){Export-AzAutomationRunbook -ResourceGroupName "ResourceGroup"
-AutomationAccountName "UserManagementTasks" -Name $b.Name -Slot "Published" -OutputFolder
"C:\temp\export"}
Position : At line:1 char:26
+ ... $runbooks){Export-AzAutomationRunbook -ResourceGroupName "ResourceGroup ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Contributor guide
Research direction
Reproduce the failure with Export-AzAutomationRunbook and the runbook name C_Create. Start at ExportAzureAutomationRunbook, then inspect AutomationPSClient.ExportRunbook and TryGetRunbookModel through RunbookOperations.GetAsync to locate the name validation. Done means runbooks containing underscores can be exported successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, powershell
- Domain
- cli, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100