使用Powershell第II部分从XML源中提取数据-从CSV中提取数据以用于特定字段或函数

时间:2019-10-23 20:20:24

标签: xml powershell

所以有两种情况: 数据源示例:

<Person lifenumber="21596" lname="LOVER" mname="J" fname="JERRY" affiliation="Hospital One" email="jerry.LOVER@mss.edu" building="" floor="" room="" phone="" hrstatus="A" active_direct_user="lassej04" active_direct_provider="HOSPITAL">
<Appointment affiliation="Hospital One" deptname="Cardiology" divname="" deptcode="821" title="ASST CLIN PROF"/>

                                     


使用的代码(带有功能)


$xmlPath = 'C:\Scripts\source.xml'
[xml]$data = Get-Content $xmlPath

#pulls everything above 'Appointment"
function Search-LifeNumber 
{
    param(
        $Source = $data,
        [Parameter(Mandatory=$true,
        Position=0)]
        $LifeNumber

    )

    $Target = $Source.People.Person | ? {$_.LifeNumber -eq $LifeNumber} 

    return $Target
}
#pulls Deptment Code data associated with targeted node
function Search-ByDepartmentCode 
{
    param(
        $Source = $data,
        [Parameter(Mandatory=$true,
            Position=0)]
        $DepartmentCode

    )

    $Target = $Source.SelectNodes('//People/Person/Appointment') | ? {$_.deptcode -eq $DepartmentCode} 

    return $Target
}

我如何才能使用包含生命编号列表的csv对函数运行?要将与该生命号相关的所有数据提取到// People / Person?


我将在另一个帖子中添加另一个代码示例。

0 个答案:

没有答案