Извлечение данных из CSV для использования с полем / функцией с помощью Powershell - PullRequest
0 голосов
/ 24 октября 2019

Образец исходных данных:

    <Appointment affiliation="Hospital One" deptname="Cardiology" divname="" deptcode="821" title="ASST CLIN PROF"/>
  </Person>
  <Person lifenumber="27901" lname="WINNER" mname="" fname="KURT" affiliation="Hospital One" email="kurt.WINNER@mss.edu" building="Annenberg" floor="17 TH FL" room="17-44" phone="(212) 241-1234" hrstatus="A" active_direct_user="hirsck01" active_direct_provider="MSSMCAMPUS">
    <Appointment affiliation="Hospital One" deptname="Pediatrics" divname="" deptcode="852" title="PROF LECTR"/>
  </Person>
  <Person lifenumber="30899" lname="OLYMPIA" mname="R" fname="MARTIN" affiliation="Hospital One" email="martin.OLYMPIA@mss.edu" building="" floor="" room="" phone="" hrstatus="A" active_direct_user="gellem03" active_direct_provider="HOSPITAL">
    <Appointment affiliation="Hospital One" deptname="Neurology" divname="" deptcode="841" title="ASSOC CLN PROF"/>
    <Appointment affiliation="Hospital One" deptname="Neurology" divname="" deptcode="105" title="ASSOC ATTN"/>
  </Person>
  <Person lifenumber="31183" lname="SCOOBY" mname="" fname="JAMES" affiliation="Hospital Two" email="" building="" floor="" room="" phone="" hrstatus="A" active_direct_user="" active_direct_provider="">
    <Appointment affiliation="Elmhurst/Queens Hospital" deptname="Otolaryngology" divname="" deptcode="A35" title="O.R. TECH"/>
  </Person>

Образец кода: благодаря Vonpryz он предоставил измененный способ извлечения данных, но теперь я все еще пытаюсь понять, как бороться сCSV избранных номеров жизни. Есть ли способ заставить вызов @lifenumber идти против группы чисел в CSV?

[xml]$p = get-content C:\Scripts\source\Hospitalone_XML.xml
# Search by lifenumber
$nl = $p.SelectNodes('/People/Person[@lifenumber="27091"]')
# Check the email
$nl.email
$nl.lname
$nl.fname
# How many appointments?
$nl.appointment.count
# See the titles
$nl.appointment | % { $_.title }
$nl.appointment | % { $_.deptcode }

1 Ответ

0 голосов
/ 24 октября 2019

Предполагается, что у вас есть CSV-файл со столбцом lifenumber:

$CSV = Import-Csv numbers.csv
[xml]$p = Get-Content C:\Scripts\source\Hospitalone_XML.xml

foreach($row in $CSV){
    $people = $p.SelectNodes(('/People/Person[@lifenumber="{0}"]' -f $row.lifenumber))
    # work with $people here
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...