Sai Vamsi
Sai Vamsi

Reputation: 141

How to use arm template deployment IPAddress output a powershell target machine ip

I am trying to deploy a vm using ARM template and use the IP of the machine as powershell target machine Ip to run scripts inside the VM that got deployed.

I added output variable in arm template which is giving the Ip address of the machine that is getting deployed.

"outputs": {
    "adminUsername": {
        "type": "string",
        "value": "[parameters('adminUsername')]"
    },
    "PublicIPAddress": {
         "type": "string",
        "value": "[reference(parameters('publicIpAddressName')).ipAddress]"
    }
}

I am capturing that Ip as Deployment Output like this enter image description here

And in the powershell task i am able to print that Ip address like this

enter image description here

But when i use the same as target machine IP like this it is saying that hostname cannot be parsed enter image description here

I am attaching the outputs that i am getting here

enter image description here

enter image description here

Can Someone help me with this? Thanks in advance.

Upvotes: 0

Views: 229

Answers (1)

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30313

It seems the Deployment Output value cannot be referenced in the task PowerShell on target machines.

Please try setting the Deployment Output to an environment variable in scripts via powershell task. See below:

Add a powershell task to run below scripts to set the Deployment Output to variable IpAddress: See here.

$var=ConvertFrom-Json '$(ArmOutput)'
$value=$var.PublicIPAddress.value
Write-Host "##vso[task.setvariable variable=IpAddress;]$value"

enter image description here

In the task PowerShell on target machines, you can reference the variable IpAddress created in above powershell task:

enter image description here

Upvotes: 1

Related Questions