-1

我对powershell很陌生,我有一个需要处理的xml文件,其中包含一堆这样的行:

<root>
  <userManagement>
    <user><account>Chico</account>
    <firstname>Leonard</firstname>
    <lastname>Marx</lastname>
    <description>Pianist</description>
    <password>Password1</password>
    <manager/>
    <ou>comedians</ou>
    <memberOf>
    <group>MBrothers</group>
    <group>GGMusicians</group>
    </memberOf>
    </user>...

我需要能够提示用户在命令行输入文件名。我如何在脚本中编写它?(显然会有更多,但我一次只工作一步)。

4

2 回答 2

2

如果用户有 Powershell V3,你可以这样做"

$XML_filpath = 'c:\XMLfiles'

$XML_file=
Get-ChildItem $XML_filpath\*.xml |
select Name |
Out-GridView -Title 'Select XML file to process' -OutputMode Single 


[xml]$xml = gc "$XML_filpath\$($XML_file.name)"
于 2013-03-18T16:53:17.950 回答
2

像这样

$filename = read-host "Insert file name to process"

[xml]$xml = gc $filename
于 2013-03-18T16:42:28.910 回答