I would like to run a PowerShell custom script inside arm template, so it sets port forwarding and set firewall, script is as following
function set-proxy {
param(
[parameter(ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, HelpMessage = "proxy informations")]
[hashtable[]]$proxyinfos
)
foreach ($proxyinfo in $proxyinfos){
netsh interface portproxy add v4tov4 listenaddress=$($proxyinfo.listenaddress) `
listenport=$($proxyinfo.listenport) connectaddress=$($proxyinfo.connectaddress) connectport=$($proxyinfo.connectport)
}
}
function set-firewall {
param(
[parameter(ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, HelpMessage = "proxy informations")]
[hashtable[]]$proxyinfos
)
foreach ($proxyinfo in $proxyinfos){
New-NetFirewallRule -DisplayName $($proxyinfo.firewallrulename) -Direction $($proxyinfo.direction) `
-LocalPort $($proxyinfo.listenport) -Protocol $($proxyinfo.protocol) -Action $($proxyinfo.action)
}
}
set-proxy $proxyinfos
set-firewall $proxyinfos
I'm hoping the proxyinfo can be passed as an array of hashtable
$proxyinfos=@(
@{
listenaddress="10.1.10.20"
listenport="443"
connectaddress="10.1.10.20"
connectport="443"
firewallrulename= "port443"
direction="Inbound"
action="Allow"
protocol="TCP"
},
@{
listenaddress="10.1.10.20"
listenport="80"
connectaddress="10.1.10.20"
connectport="80"
firewallrulename= "port80"
direction="Inbound"
action="Allow"
protocol="TCP"
}
)
But I'm a bit stuck trying to see how I can pass it from arm template parameter file.
If I create an array parameter called proxyinfos
"proxyinfos": {
"value": [
{
"listenaddress": "10.1.10.20",
"listenport": "443",
"connectaddress": "10.1.10.20",
"connectport": "443",
"firewallrulename": "port443",
"direction": "Inbound",
"action": "Allow",
"protocol": "TCP"
},
{
"listenaddress": "10.1.10.20",
"listenport": "80",
"connectaddress": "10.1.10.20",
"connectport": "80",
"firewallrulename": "port80",
"direction": "Inbound",
"action": "Allow",
"protocol": "TCP"
}
]
}
got it working in the end when passing paramater, gotta do this
so when passing this paramater to powershell, the json looks something like this
and inside powershell