我对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>...
我需要能够提示用户在命令行输入文件名。我怎么写脚本? (显然会有更多的东西,但我一步一步地工作一步)。
答案 0 :(得分:2)
$filename = read-host "Insert file name to process"
[xml]$xml = gc $filename
答案 1 :(得分: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)"