I am trying to read the output values from ARM template in post deployment script file. Can you give me the syntax to read those values? - azure

I am trying to read the output values from ARM template in post deployment script file. Can you give me the syntax to read those values?

You could retrieve the out value from a linked template by using reference function.
retrieve the property value with syntax like: "[reference('<name-of-deployment>').outputs.<property-name>.value]"
Note: You cannot use the reference function in the outputs section of a nested template. To return the values for a deployed resource in a nested template, convert your nested template to a linked template.
If Powershell command is possible, we could get the following command
$deploy = New-AzureRmResourceGroupDeployment -Name $deployment -ResourceGroupName $resourceGroupName -TemplateFile $deployJsonFilePath -TemplateParameterFile $deployJsonParameterFilePath
$outPuts = $deploy.Outputs

Related

resource cleanup which are only tagged to specific tag

I am using the below AZ script to delete the tag for a resource. But I want only specific tag needs to be deleted not all the tags that are associated with resource. Example
There is tag name "Business unit" value 101, below are the resource name which are inside this tag:
hrm01vm, hrmvnet, hrmappservice
The above resource are also associated with other tags as well like "Department" & "supportedby"
az tag delete --resourceid --yes -y
This deletes the entire tags which are associated with the resource. I want only "Businessunit" tags to be deleted. Any command that I need to include?
Parameters in PS.
After reproducing from my end, I could able to achieve this using Remove("<Key>"). Below is the complete script that worked for me.
$a = Get-AzResource -ResourceGroupName <RESOURCE_GROUP> -Name <FUNCTION_APP>
$a.Tags.Remove("<YOUR_REQUIRED_TAG>")
$a | Set-AzResource -Force
RESULTS:
After execution

Create and Writing into a .tempo file using PowerShell Script with variables passed, a specific format

I would like to create a abcd.tempo file using powershell and want to add the content in the below format :
Startdate:12/06/2020
ParamVar2:RISPA
ParamVar3:MLPL
CNTRY=USA
the above is the targeted format , i need to insert into the abcd.tempo file.
Startdate is a variable used and similar to this, other variables as well.
what i meant,Startdate, ParamVar2 , ParamVar3, CNTRY are hardcoded labels and these parameters would be filled with the dynamic values fetched from other code block in my same powershell file.
At present, am able to create a new abcd.tempo file using
new-item -filepath "$myfilepath2createFile" -itemtype File
and i added some dummy content inside that. but
am not able understand how can i create the similar structure , written above.
Another requirement is to call a EXE file from this powershell script and pass anotehr 4 parameters to the EXE
Though i used
Start-Process -FilePath $script:testingexeFile
am stuck at how to pass the 4 parameters to this EXE

Calling a PowerShell script from Azure batch custom activity

I am trying to run a PowerShell script from within an Azure, Data Factory, Batch Service, Custom Activity. The closest I've gotten to this working is the following:
powershell powershell -command '$env:AZ_BATCH_TASK_DIR\wd\processInAzure.ps1'
When I run this I get the following error message
At line:1 char:23
+ $env:AZ_BATCH_TASK_DIR\wd\processInAzure.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '\wd\processInAzure.ps1' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
I've been able to get a directory listing of $env:AZ_BATCH_TASK_DIR\wd and see that processInAzure.ps1 exists at this location. I've been able to Write-Host "Hello from Azure" so I can see powershell is working. What I'm not getting is how to reference the ps1 script file using an environment variable. Would anyone know the syntax sugar to get this working?
With Architect Jamie's input (including his deleted edit!!! Put edit back it directly led to the solution) I was able to put a few things together to get this to work. The double powershell at the beginning of the command line is not a typo BTW. This is what ended up working:
powershell powershell -command ("$env:AZ_BATCH_TASK_DIR" + '\wd\processInAzure.ps1')
What didn't work is the following:
powershell powershell -command ("$env:AZ_BATCH_TASK_DIR" + "\wd\processInAzure.ps1")
powershell powershell -command ("$env:AZ_BATCH_TASK_DIR\wd\processInAzure.ps1")
powershell -command ("$env:AZ_BATCH_TASK_DIR" + '\wd\processInAzure.ps1')
Try this:
powershell -command "$($env:AZ_BATCH_TASK_DIR)\ws\processInAzure.ps1"
It's not possible to access object member properties or methods inside single quote qualified strings. Using the double quote in PowerShell allows you to expand variables at runtime.
Edit:
Though the above is true, in this instance the reason for the error is that PowerShell is treating the path being tacked on as part of the environment variable identifier. Using $() variable expansion as above will work, and you should also be able to use ('$env:AZ_BATCH_TASK_DIR' + '\ws\processInAzure.ps1')

Azure pipeline concatenating variable names and accessing new variable value

In my Azure pipeline I have 2 vairables $name1 = hello $name2 = world. Those variable value change at run time.
I can concatenate those 2 variable value which will create $helloworld variable.
How do I access $helloworld value? $Helloworld variable is also declared in the pipeline
I'm trying to pass the value of this variable as an argument to the powershell
The following doesn't seem to work $($(name1)$(name2))
You just need to refer it as,
Let's say you had $name1 = 'hello' and $name2 = 'world'.
$($name1)$($name2) = 'helloworld'
You may use $helloworld = "$name1 $name2", please have a try.
The update:
Please have a try with the commands below:
$name1 = "h"
$name2 = "w"
New-Variable -Name "${name1}${name2}" -Value 'helloword' -Force
$hw
Azure pipeline concatenating variable names and accessing new variable value
AFAIK, this issue is about nested variables rather than the concatenate variable.
As you test, you can get the helloworld by the ($name1)($name2), but we could not access value in $helloworld by the nested variable $($(name1)$(name2)).
That is because the value of nested variables (like $($(name1)$(name2))) are not yet supported in the build pipelines at this moment.
You could add your request for this feature on our UserVoice site (https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ), which is our main forum for product suggestions.
Hope this helps.

Call Set-AzureRmAppServicePlan cmdlet with arbitrary parameters

I want to call Set-AzureRmAppServicePlan with arbitrary parameters, the list of parameters is defined in runtime and is not set statically.
In other languages like Perl I would use Hash for this, but I get stuck here in Powershell even though I know that Powershell supports HashTables.
Following example does not work
$params = #{}
$params.add('-WorkerSize', 'Small');
$params.add('-NumberofWorkers', '2');
Set-AzureRmAppServicePlan -ResourceGroupName 'RG1' -Name 'AppServicePlna1' $params
I get Set-AzureRmAppServicePlan : Long running operation failed with status 'BadRequest'. error from Azure.
PowerShell does support what you are trying to do. It is known as splatting.
In your case, you have a minor typo. All you need to do is change the $ to an # in this line:
Set-AzureRmAppServicePlan -ResourceGroupName 'RG1' -Name 'AppServicePlna1' $params
So the working version looks like this:
Set-AzureRmAppServicePlan -ResourceGroupName 'RG1' -Name 'AppServicePlna1' #params
The issue is not with PowerShell per say.
Last time I checked you cannot pass 'Parameter key' for an Azure Module command.

Resources