Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Azure Powershell中的虚拟机名称拆分为多个部分_Azure_Powershell_Split_Tags_Virtual Machine - Fatal编程技术网

将Azure Powershell中的虚拟机名称拆分为多个部分

将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

在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 -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(变量名不应以数字开头)

非常感谢你,你是个救生员!我没想到会那么容易。