我需要 PowerShell 脚本每次在结帐后读取并增加 json 文件中的值,即 value": "AEU-EHSSAS19" should change AEU-EHSSAS20

I need PowerShell script to read and increment value inside json file everytime after checkout i.e. value": "AEU-EHSSAS19" should change AEU-EHSSAS20

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "adminUsername": {
      "value": "APORIA"
    },
    "adminPassword": {
      "value": "Password@1234"
    },
    "VMName": {
      "value": "AEU-EHSSAS19"
    },
    "VMSize": {
      "value": "Standard_B2ms"
    },
    "LabName": {
      "value": "EUW-TSE-D-SELFSERV"
    },
      "windowsOSVersion": {
      "value": "2016-Datacenter"
    }     
    }
  }

PowerShell script to read and increment value inside json file everytime after checkout

参考以下PowerShell脚本:

$pathToJson = "path/test.json"
$a = Get-Content $pathToJson | ConvertFrom-Json

$VMName = $a.parameters.VMName.value
echo $VMname
$len = $VMName.Length
$number= "$VMName".Substring($len - 2, 2)
echo $number

$number = [int]$number+1

echo $number

$NewVMName = $VMName.replace('19',$number)

echo $NewVMName

$a.parameters.VMName.value = $NewVMName

$a | ConvertTo-Json | set-content $pathToJson

PowerShell 脚本将查找 VMName 字段的值。然后它会得到字符串中的数字和增量+1.

结果: