marge使用powershell嵌入JSON对象

marge使用powershell嵌入JSON对象,json,powershell,Json,Powershell,我从Json文件的Json输出中获得以下转换: Id : 1 ItemName : TestFile SharingInformation : {@{RecipientEmail=complianceadmin@dev.onmicrosoft.com; ResharePermission=Read}, @{RecipientEmail=test@dev.onmicrosoft.com; ResharePermission=Read}} 我想以

我从Json文件的Json输出中获得以下转换:

Id                 : 1
ItemName           : TestFile
SharingInformation : {@{RecipientEmail=complianceadmin@dev.onmicrosoft.com; ResharePermission=Read}, @{RecipientEmail=test@dev.onmicrosoft.com; ResharePermission=Read}}
我想以以下列的方式将此数据保存到.csv文件中:

Id                 : 1
ItemName           : TestFile
Users              : (read) test@dev.domain.com ; (write) test2@dev.domain.com
作为列。。在这里,您可以找到我的部分实际PS代码(当有多个嵌入值时,这些代码无法正常工作):

你对如何实现这一目标有什么想法吗

谢谢你的帮助!
关于

您可以将共享信息格式化为您喜欢的任何形式

试一试


这是有效的:)有没有办法通过$shareInfo.ResharePermission对值进行排序?@anders1990你可以做
$users=foreach($shareInfo-in($).SharingInformation | sort-Object-ResharePermission){({0}){1}'-f$shareInfo.ResharePermission,$shareInfo.RecipientEmail}
$JSONFile = $ExctratedFile | ConvertFrom-Json
$psObjectForCsv = $JSONFile | ForEach-Object {
    [PSCustomObject]@{
        "id"=$_.Id
        "ItemName"=$_.ItemName
        "RecipientEmail"=$_.SharingInformation.RecipientEmail
        "ResharePermission"=$_.SharingInformation.ResharePermission

    }
}
$psObjectForCsv | Export-Csv -path $fileName -Force -NoTypeInformation
} 
$JSONFile = $ExctratedFile | ConvertFrom-Json
$result   = $JSONFile | ForEach-Object {
    # output a formatted string "(permission) emailaddress" 
    $users = foreach ($shareInfo in $_.SharingInformation) {
        '({0}) {1}' -f $shareInfo.ResharePermission, $shareInfo.RecipientEmail
    }
    [PSCustomObject]@{
        id       = $_.Id
        ItemName = $_.ItemName
        Users    = $users -join "; "
    }
}

$result | Export-Csv -Path $fileName -Force -NoTypeInformation