xml - 使用 Powershell 将值写入 xml 文件
问题描述
我有一个 PS 脚本来从 XML 文件中读取值:
PS D:\> $xml = [xml](Get-Content C:\Users\myuser\.VirtualBox\VirtualBox.xml)
PS D:\> $VMFolder = $xml.VirtualBox.Global.SystemProperties.defaultMachineFolder
PS D:\> echo $VMFolder
D:\VirtualboxVMs
xml文件示例:
<VirtualBox xmlns="http://www.virtualbox.org/" version="1.12-windows">
<Global>
<SystemProperties defaultMachineFolder="D:\VirtualboxVMs" defaultHardDiskFormat="VDI" VRDEAuthLibrary="VBoxAuth" webServiceAuthLibrary="VBoxAuth" LogHistoryCount="3" exclusiveHwVirt="false"/>
</Global>
</VirtualBox>
谁能给我一个例子,如何使用 PowerShell 将 defaultMachineFolder="D:\VirtualboxVMs" 的值更改为 "D:\newlocation"?
解决方案
就像是
$xml.VirtualBox.Global.SystemProperties.defaultMachineFolder = "D:\VirtualboxVMs"
$xml.Save("C:\Users\myuser\.VirtualBox\VirtualBox.xml")
应该做的伎俩
推荐阅读
- django - 捕获从 celery 任务发送的 django 信号
- javascript - 引导日期时间选择器插件?
- functional-programming - 方案大于平均功能
- javascript - 验证对象数据是否为“真”,如果是则检索相关数据
- javascript - D3.js 和嵌套数据 - 为什么我的 exit() 设置为空
- ibm-watson - 在 Watson Studio 中创建实验时出错
- azure-language-understanding - LUIS 应用中的模式识别:请查找 {Entity1} {Entity2}{Entity3} 文档
- python - 查询dict python http请求
- c++ - 无法访问 C++ 标头
- django - django-admin 指向 virtualenv 之外