首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >编辑xml文件中的节点值,并使用powershell以随机数进行更新

编辑xml文件中的节点值,并使用powershell以随机数进行更新
EN

Stack Overflow用户
提问于 2019-03-04 00:02:22
回答 1查看 0关注 0票数 0

我喜欢用powershell编辑节点并用随机数更新它

xml文件节点

  <?xml version="1.0" encoding="utf-8" ?>
    <Configuration>
        <Other appsCode="V7{}appsCont-12-Win-GM">
            <Data key="appsnumbers">970767075516458272844213</Data>
        </Other>

</Configuration>

脚本

# load XML file into local variable and cast as XML type.
$doc = [xml](Get-Content ./test.xml)

$doc.root.one                                  

# find the value *970787075519458272844213* in the node and create a new one and update the xml files 


$doc.save("./testNew.xml")
EN

回答 1

Stack Overflow用户

发布于 2019-03-04 09:32:18

IIRC $ doc.save()不接受相对路径。

根据mklement0的良好提示,我选择的补救措施是可以的,而原因并没有达到目的

## Q:\Test\2019\03\03\SO_54972848.ps1
$FileIn = ".\test.xml"
$FileOut= Join-Path (Get-Item .) "testNew.xml"

$doc = [xml](Get-Content $FileIn)

$doc.Configuration.Other.Data.'#text'
$doc.Configuration.Other.Data.'#text' = -join (1..24|%{get-random -min 0 -max 9})
$doc.Configuration.Other.Data.'#text'

$doc.save($FileOut)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100006410

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档