使用 azure powershell 更改 VMConfig 文件
Change VMConfig file using azure powershell
我有一个 vmConfig 文件。我想更改子网和 IP 地址,因为我想在新子网的配置文件中创建一个新的 VM,其余所有配置都不需要更改。我可以手动编辑 xml 文件内容,但我想通过 powershell 来完成,这样我就可以对所有内容进行自动化处理。
这是示例 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 />
我只对更改 IP 地址和子网感兴趣。
这基本上是 xml 使用 powershell 进行解析。我希望这对你有用 -
$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)
我有一个 vmConfig 文件。我想更改子网和 IP 地址,因为我想在新子网的配置文件中创建一个新的 VM,其余所有配置都不需要更改。我可以手动编辑 xml 文件内容,但我想通过 powershell 来完成,这样我就可以对所有内容进行自动化处理。
这是示例 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 />
我只对更改 IP 地址和子网感兴趣。
这基本上是 xml 使用 powershell 进行解析。我希望这对你有用 -
$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)