Alex
Alex

Reputation: 345

Change VMConfig file using azure powershell

I have a vmConfig file. I want to change subnet and IP Address as I want to create a new VM out of config file in new subnet, rest all configurations no need to be changed. I can manually edit xml file content but I want to do it through powershell so that I can have an automated process for everything.

Here is the sample 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 am interested changing only IP Address and Subnet.

Upvotes: 3

Views: 137

Answers (1)

Aatif Akhter
Aatif Akhter

Reputation: 2206

This is basically xml parsing using powershell. I hope this should work 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)

Upvotes: 2

Related Questions