Это, вероятно, просто, но я пытаюсь определить, существует ли узел в документе XML. Я думал, что нашел ответ в этом посте, How to check whether a node exists or not using powershell without getting exception?, но я не получил его на работу. Это моя последняя попытка.Определить существующий XML-узел
foreach ($vendor in $xml.Vendors.Vendor| Where-Object {$_.Type -match "Send"}) {
$NodeExists = $vendor.SelectSingleNode($vendor.EncKey)
if ($NodeExists -ne $null) {
# Do something
}
else {
# something else
}
}
Любая помощь была бы принята с благодарностью.
EDIT: Вот XML из моего тестового файла. Мне нужно выяснить, существует ли EncKey или отметить для каждого поставщика.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Vendors we will send and retreive files from Get-Send means we will get a file and send them a file Send means we will only send them a file-->
<Vendors>
<Vendor Type="Get-Send">
<Name>Vendor1</Name>
<RemotePath>/Remote/Path1/</RemotePath>
<EncKey>pgpenc.key</EncKey>
</Vendor>
<Vendor Type="Send">
<Name>Vendor2</Name>
<RemotePath>/Remote/Path2/</RemotePath>
<!-- This one has no EncKey -->
</Vendor>
</Vendors>
Не могли бы вы предоставить пониженную тестовый пример для выпуска ? Что-то мы можем вставить в наш любимый редактор Powershell и поиграть с ним? – Neolisk