我认为我从脚本的其余部分得到了我需要的东西,我只需要帮助查询和读取XML文件,然后通过脚本的其余部分进行管道处理。如果有人能指出我正确的方向,我将非常感激。
param([string] $file)
try {
$ErrorActionPreference = "Stop"
$xml = [xml](Get-Content $file)
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Host "File not found."
} catch {
Write-Host "Please enter a file path."
}
答案 0 :(得分:0)
使用Read-host从用户那里获取输入,并使用循环确保路径存在,如下所示:
param([string] $file)
try {
$ErrorActionPreference = "Stop"
$xml = [xml](Get-Content $file)
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Host "File not found."
} catch {
Do
{
$XMLFile = Read-Host "Please enter a file path"
}
until (Test-Path $XMLFile)
$xml = [xml](Get-Content $XMLFile)
}