Modify VMConfig file with azure powershell

I have a vmConfig file. I want to change the subnet and IP address as I want to create a new VM from the config file on the new subnet, the rest of the settings do not need to be changed. I can manually edit the content of the xml file, but I want to do it through powershell so that I have an automatic process for everything.

Here is an example vmConfig xml -

<?xml version="1.0" encoding="utf-8"?>
<PersistentVM xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ConfigurationSets>
    <ConfigurationSet xsi:type="NetworkConfigurationSet">
      <ConfigurationSetType>NetworkConfiguration</ConfigurationSetType>
      <InputEndpoints>
        <InputEndpoint>
          <LocalPort>5986</LocalPort>
          <Name>PowerShell</Name>
          <Port>64929</Port>
          <Protocol>tcp</Protocol>
          <Vip>191.237.20.225</Vip>
          <EnableDirectServerReturn>false</EnableDirectServerReturn>
          <IdleTimeoutInMinutes xsi:nil="true" />
        </InputEndpoint>
      </InputEndpoints>
      <SubnetNames>
        <string>mysubnet</string>
      </SubnetNames>
      <StaticVirtualNetworkIPAddress>12.13.14.15</StaticVirtualNetworkIPAddress>
      <PublicIPs />
      <NetworkInterfaces />

      

I'm only interested in changing the IP address and subnet.

+3


source to share


1 answer


It's basically xml parsing using powershell. I hope this works for you -



$path = 'C:\myFolder\XmlVM.xml'
[xml]$myXML = Get-Content $path
$myXML.PersistentVM.ConfigurationSets.ConfigurationSet.SubnetNames.string="MYNEWSUBNET"
$myXML.PersistentVM.ConfigurationSets.ConfigurationSet.StaticVirtualNetworkIPAddress="10.11.14.115"
$myXML.Save($path)

      

+2


source







All Articles