将Azure Powershell中的虚拟机名称拆分为多个部分
在Azure中创建新vm时,我希望将其vmname拆分为块,以便将它们分配到变量中。稍后,我想使用它们将标签分配到vm中。命名约定如下所示:将Azure Powershell中的虚拟机名称拆分为多个部分,azure,powershell,split,tags,virtual-machine,Azure,Powershell,Split,Tags,Virtual Machine,在Azure中创建新vm时,我希望将其vmname拆分为块,以便将它们分配到变量中。稍后,我想使用它们将标签分配到vm中。命名约定如下所示: $vmnane = 11111233444 split-string $wmname -some kind of string division definition command $2 = 2 $3 = 33 $4 = 444 $r = Get-AzureRmResource -ResourceName $vmname -ResourceGroupNa
$vmnane = 11111233444
split-string $wmname -some kind of string division definition command
$2 = 2
$3 = 33
$4 = 444
$r = Get-AzureRmResource -ResourceName $vmname -ResourceGroupName examplegroup
Set-AzureRmResource -Tag @{ firsttag="$2"; secondtag="$3" etc...} -ResourceId $r.ResourceId -Force
1111133444
我想要实现的是分割vmname并将其分配为如下变量:
$vmnane = 11111233444
split-string $wmname -some kind of string division definition command
$2 = 2
$3 = 33
$4 = 444
$r = Get-AzureRmResource -ResourceName $vmname -ResourceGroupName examplegroup
Set-AzureRmResource -Tag @{ firsttag="$2"; secondtag="$3" etc...} -ResourceId $r.ResourceId -Force
我该怎么办?我很难在网上找到解决办法 这应该有效:
$vmname = 11111233444
$vmname -match '^(.{5})(.{1})(.{2})(.{3})'
$a = $Matches[1]
$b = $Matches[2]
$c = $Matches[3]
$d = $Matches[4]
正则表达式匹配vm名称的前五个、下一个、后面两个和最后三个字符,并将它们分配给变量$a、$b、$c、$d(变量名不应以数字开头) 非常感谢你,你是个救生员!我没想到会那么容易。