我试图将 .xml 文件导出到 .csv 文件(多个 .xml 文件到一个 .csv 文件)这是我的工作代码:
$path = "C:\Temp\Cert\"
$FileLogdate = Get-Date -format 'dd_MM_yyyy'
$exportpath = "C:\Temp\Cert\$FileLogdate-sdf.csv"
Get-ChildItem $path -filter *.xml |
ForEach-Object {
[xml]$empDetails = Get-Content $_.Fullname
$empDetails.Objs.Obj |
% {
[pscustomobject] @{
"Client" = $_.ms.s.innertext
"CertificateExpire" = $_.ms.dt.innertext
}
} |
ConvertTo-Csv -NoTypeInformation
}
现在我遇到了问题,客户端和证书上可能有多个条目,如下所示:
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
<Obj RefId="0">
<TN RefId="0">
<T>Selected.System.Security.Cryptography.X509Certificates.X509Certificate2</T>
<T>System.Management.Automation.PSCustomObject</T>
<T>System.Object</T>
</TN>
<MS>
<DT N="NotAfter">2022-12-31T08:21:10+01:00</DT>
<S N="Subject">Client 01</S>
<S N="Issuer">DOMAIN</S>
</MS>
</Obj>
<Obj RefId="1">
<TNRef RefId="0" />
<MS>
<DT N="NotAfter">2022-12-31T08:21:10+01:00</DT>
<S N="Subject">Client 01</S>
<S N="Issuer">DOMAIN</S>
</MS>
</Obj>
</Objs>
我怎样才能解决输出不像:
"Client 01 Client 01", "Client 01 Client 01", "2022-12-31T08:21:10+01:00 2022-12-31T08:21:10+01:00"