Starting Runbook via Azure API, Portal, or ISE Add-On yields "input parameter type mismatch" error - powershell

Given a simple runbook:
workflow test
{
[CmdletBinding()]
param([string] $NumericString)
write-output $NumericString
}
When starting it with a numeric value (ie: 5) via the Azure Portal as a new Job (published), via the Test Pane, or using the Azure Automation PowerShell ISE Add-On, the following error is returned and the execution Fails.
[edit] Just out of curiosity I tried some other values. 'true' or 'false' (without quotes in ise/the ui) will also cause the error (and are sent to the API inside quotes).[\edit]
The values provided for the root activity's arguments did not satisfy
the root activity's requirements: 'DynamicActivity': Expected an input
parameter value of type 'System.String' for parameter named 'Numeric'.
Parameter name: rootArgumentValues
AFAIK, this is not a factor when I've executed via a parent runbook, webhook, etc.
The PowerShell ISE Add-On issues this PUT request to the API:
(https://management.azure.com/subscriptions/<id>/resourceGroups/<rg>/providers/Microsoft.Automation/automationAccounts/<aa>/runbooks/<rb>/draft/testJob?api-version=2015-10-31)
{
"parameters": {
"Numeric": "5" <-- notice it's a string
}
}

This is a bug in the Automation portal and ISE add on. For portal, this should be fixed in a week or so. For ISE add on, can you please file a bug on this here: https://github.com/azureautomation/azure-automation-ise-addon/issues

This would appear to be a bug, similar to Azure Automation Error 'DynamicActivity': Expected an input parameter value of type
To mitigate the issue, just wrap your numeric value in quotes in the Portal or ISE Add-On
If you are starting runbooks outside of the formal SDKs, it appears you need to know about required extra escaping for sending Numeric or Boolean values for string parameters (in the least).
This is what the subsequent PUT request should look like (from ISE Add-On)
{
"parameters": {
"Numeric": "\"5\""
}
}

Related

Azure DevOps Pipeline - Create a Synapse managed-private-endpoints to a Azure Storage Account

I am trying to create a 'Synapse Managed private endpoint' to an Azure storage account via a 'Azure cli' task as a step in a pipeline. I want to create the MPE automatically.
The pipeline step calls a power-shell script with parameters. The script is located in source control. Calling the script and passing in parameter values is working fine.
Within the powershell script the following happens...
Get the json template (see below) from source control - this step works.
In the powershell script subsitute the json fields enclosed in <...> with a the parameter values passed in to the power-shell script - this works fine. The converted json is shown in the below screenshot.NB: sensitive values have been readacted here but look correct...
The line in the power-shell that's raising the error is...
az synapse managed-private-endpoints create --workspace-name "$pSynapseWorkspaceName" --pe-name "$pPrivateEndpointName" --file $mpeArmJson --debug --verbose
I think it's to do with the json-string parmater $mpeArmJson and double-quotes - this is what I need help solving ???
The value of $mpeArmJson which the value at this point is (note sensitive values have been readacted here but look correct)...
{
"name": "dds2-datalake-endpoint",
"properties": {
"privateLinkResourceId": "/subscriptions/<redacted subscription id>/resourceGroups/dds2-data-tst-rg/providers/Microsoft.Storage/storageAccounts/dds2datatstdlksa",
"groupId": "dfs",
"fqdns": [
"<redacted-storage-account>.dfs.core.windows.net"
]
}
}
In my Azure devOps pipeline I have created a 'Azure Powershell' task. The task calls a PowerShell script stored in source-control - taking in parameters.
Inside the powershell script I am calling...
New-AzSynapseManagedPrivateEndpoint -WorkspaceName "$pSynapseWorkspaceName" -Name "$pPrivateEndpointName" -DefinitionFile "$tmpDir"
NB: the devOps pipeline runs under a Az 'service principal' which creates the Synapse workspace and in doing so gets the 'owner' and also a 'synapse admin.' permissions automatically set in IAM.
The 'service principal' also needs 'blob storage data contributor' on the main storage account linked to Synapse.

How to fix PipelineParam from discarding all information except for name in Kubeflow Pipeline

I'm trying to write an application using Kubeflow Pipelines. I'm running into trouble when passing in parameters to the pipeline (the main python function decorated with #kfp.dsl.pipeline). The parameters should be automatically converted into a PipelineParam with name, value, etc info. However, it seems that everything except for the name is being discarded. I'm on an Ubuntu server.
I've tried uninstalling/reinstalling and updating Kubeflow, tried installing several of the most recent versions of kfp (0.1.23, 0.1.22, 0.1.20, 0.1.18), as well as installing on my local machine.
def print_pipeline_param():
return(kfp.dsl.PipelineParam("Name", value="Value"))
#kfp.dsl.pipeline(
name='Test Pipeline',
description='Test pipeline'
)
def test_pipeline(output_file='/output.txt'):
print(print_pipeline_param())
print(output_file)
if __name__ == '__main__':
import kfp.compiler as compiler
compiler.Compiler().compile(test_pipeline, __file__ + '.tar.gz'
The result of running this is:
{{pipelineparam:op=;name=Name;value=Value;type=;}}
{{pipelineparam:op=;name=output-file;value=;type=;}
I should be getting '/output.txt' in the "value" field, but the only field populated is the name. This only happens when passing in parameters to the main pipeline function. This also happens when directly passing in a PipelineParam like so:
#kfp.dsl.pipeline(
name='Test Pipeline',
description='Test pipeline'
)
def test_pipeline(output_file=kfp.dsl.PipelineParam("Output File", value="/output.txt")):
print(output_file)
Prints out: {{pipelineparam:op=;name=output-file;value=;type=;}

Mule PowerShell Connector - The variable '$<variable-name>' cannot be retrieved because it has not been set

Can't figure out why my variable in my PowerShell script keeps saying the variable is null (Error: The variable '$' cannot be retrieved because it has not been set.)
Mule Flow = HTTP --> Set Payload --> PowerShell --> Logger --> End
~ MULE XML Code Snippet - Using PowerShell Connector 3.x version ~
<powershell:execute config-ref="PowerShell" doc:name="PowerShell" scriptFile="classpath:powershell-script.ps1">
<powershell:parameters>
<powershell:parameter key="variable1">#[groovy: payload.variable1 ?: '']</powershell:parameter>
<powershell:parameter key="variable2">#[groovy: payload.variable2 ?: '']</powershell:parameter>
<powershell:parameter key="variable3">#[groovy: payload.variable3 ?: '']</powershell:parameter>
<powershell:parameters>
<powershell:execute>
~ PowerShell Code ~
Set-StrictMode -Version Latest
Param($variable1, $variable2, $variable3)
#Create NEW AD accounts
Function Start-Commands
{
Write-Output "Start-Commands"
Write-Output "Parameters-: $variable1 - $variable2 - $variable3"
}
Start-Commands
~ Console Output ~
Root Exception stack trace:
org.mule.modules.powershell.PowershellException: The message could not be sent. An exception has been thrown: [{"Exception":"System.Management.Automation.RuntimeException: The variable '$flowVarManager' cannot be retrieved because it has not been set.\r\n
You've since stated that Mule as the environment from which PowerShell is invoked is incidental to the problem.
The symptom - error The variable '<name>' cannot be retrieved because it has not been set. - indeed implies that a variable is being accessed that has never been set (initialized), and this kind of error is only raised if Set-StrictMode -Version 1 or higher is in effect.
-Version 1 still allows unset variables inside expandable strings (e.g., "$noSuchVar"), but -Version 2 and above does not.
It's fair to assume that you're not on PowerShell v1 (where -Version Latest would imply -Version 1), so any reference to an unset variable encountered during execution would trigger the error.
However, the parameter variables that PowerShell implicitly manages (as part of the param(...) block) are not subject to Set-StrictMode checking, as the following example demonstrates:
PS> Set-StrictMode -Version Latest; & { param($paramVar1) "[$paramVar1]" }
[]
Note: & { ... } uses &, the call operator, to execute a script block { ... }, but such a script block behaves just as a script would.
As you can see, even though no argument was passed to parameter -paramVar1 - i.e., no value was bound to the underlying $paramVar1 parameter variable - accessing $paramVar1 did not cause an error, evaluated to $null, which in the context of string interpolation becomes the empty string.
Contrast this with referencing a truly unset variable:
PS> Set-StrictMode -Version Latest; & { param($paramVar1) "[$somveVar]" }
The variable '$somveVar' cannot be retrieved because it has not been set.
Because $someVar wasn't ever set (and isn't a parameter variable), it triggered the error.
Therefore, we can observe the following about the code printed in the question as of this writing, reproduced here:
# NOTE: This code is syntactically invalid due to the placement
# of the Set-StrictMode call.
Set-StrictMode -Version Latest
Param($variable1, $variable2, $variable3)
#Create NEW AD accounts
Function Start-Commands
{
Write-Output "Start-Commands"
Write-Output "Parameters-: $variable1 - $variable2 - $variable3"
}
Start-Commands
Firstly, the Set-StrictMode call cannot be placed above the param(...) block, as the latter must be the first statement in a script.
Secondly, given that the error message complains about a variable named $flowVarManager and given that the code makes no reference whatsoever to that variable, the quoted code alone cannot be the source of the problem.
To fix the issue I removed Set-StrictMode -Version Latest
Based off my research I found this article -> https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-strictmode?view=powershell-6
The Set-StrictMode cmdlet configures strict mode for the current scope and all child scopes, and turns it on and off. When strict mode is on, Windows PowerShell generates a terminating error when the content of an expression, script, or script block violates basic best-practice coding rules.
When Set-StrictMode is ON it is interfering with the passing of the parameter values from the MS PowerShell Connector - Mule 3 to the PS script. Upon removing the line of code, the parameters were getting set with values.

Update-AzureRmEventGridSubscription setup subject prefix/postfix to string empty

I have PowerShell script to update EventGrid subscriptions. One of possible scenarios is to set subscription subject prefix/postfix to define value.
Update-AzureRmEventGridSubscription -ResourceGroup $ResourceGroupName -TopicName $EventGridTopicName -EventSubscriptionName $Subscription.name -SubjectEndsWith $Subscription.subjectEndsWith
When value is not null or empty then it works fine. But when it needs to be set to '' it throws
Cannot validate argument on parameter 'SubjectBeginsWith'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again
Should I recreate subscription?
This looks to be a bug in the Update-AzureRmEventGridSubscription implementation, thanks for reporting this! I have filed an issue at https://github.com/Azure/azure-powershell/issues/6331 to track this issue.
Until this is fixed in the EventGrid PowerShell module, the workaround would be to:
1) Either delete and re-create the event-subscription, or
2) to use the equivalent command in Azure CLI (az eventgrid event-subscription update --resource-group your-rg-name --topic-name your-topic-name --name your-event-subscription-name --subject-ends-with "").

msdeploy via powershell and psake fails

So I'm trying to use powershell and psake for my build and deployment. I've tried without any success to call the following psake task.
Exec { msdeploy.exe "-verb:sync"
"-source:package="D:\path-to-package\zip-file-name.zip"
"-dest:auto,computername=http://my-server-name-here:8090/MsDeployAgentService2/" -setparam:Name="IIS Web Application Name,Value=iis-web-app-name-here" "-allowUntrusted" }
So in an effort to get things moving I removed the offending setparam:Name="IIS Web Application Name,Value=iis-web-app-name-here". It worked but took the IIS Web Application Name parameter from the ..SetParameters.xml as expected.
<setParameter name="IIS Web Application Name" value="Default Web Site/project.name_deploy" />
There's clearly something wrong with the syntax of setparam:Name="IIS Web Application Name,Value=iis-web-app-name-here" but I've tried a dozen (or more) variations including
-setparam:"IIS Web Application Name=iis-web-app-name-here" > omitting the name,value
-setparam:"IIS` Web` Application` Name=iis-web-app-name-here" > using back ticks
I really can't work out what I'm doing wrong and may have to resort back to using an msbuild file to get things moving.
The error I receive is : > all arguments must begin with -
I believe you need to quote the parameters as follows:
setparam:Name="IIS Web Application Name",Value="iis-web-app-name-here"
Note the additional quotes before the comma and after the equals sign following Value.