Forum Discussion
majeranr
Jul 20, 2022Copper Contributor
Mapping cmdlet to variable as string
Hi, I'm having a trouble with a part of code for script. I've got a function: function Add-Resource
{
Param(
[Parameter(Mandatory = $true)] [String] $resourceToC...
majeranr
Jul 20, 2022Copper Contributor
farismalaeb that's why I used this:
$dnsVnetLink = "az network private-dns link vnet create" `
+ " --resource-group $resourceGroupName" `
+ " --zone-name $dnsZoneName" `
+ " --name `"$vnetName-DnsLink`"" `
+ " --virtual-network $vnetId" `
+ " --registration-enabled `"false`""
As an input finally, but is there a way to make it up into single string? As far as I know there's no escape character inside of the string, since backtick ( ` ) doesn't work inside strings. I'm looking for the simplest way to pass it as a string or, if someone knows a better way, for a better solution to write a re-usable code instead of using DoUntil loop function.
farismalaeb
Jul 20, 2022Iron Contributor
You can use the Here-String
something like this
$dnsVnetLink =@"
az network private-dns link vnet create
--resource-group $resourceGroupName
--zone-name $dnsZoneName" `
--name `"$vnetName-DnsLink`"" `
--virtual-network $vnetId" `
--registration-enabled `"false`"
"@
It start with @ and double-quote and ends with double-quote and @