我正在尝试获取 .json 文件的格式,该格式在使用 .json 时会提供正确的输出| ConvertFrom-Json
。我倾向于丢失很多信息,并且返回的对象不能作为所需函数的输入来展平 .json 文件。
我想从中获得正确的输出,ConvertFrom-Json
以便它与脚本一起使用:Convert-JsonToCsv.ps1
from this GitHub page。
我有以下 .json 文件
[
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027670ed8e1-25f4-4c24-b9ea-04b861a4566f\u0027)",
"enabled": false
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u00273705e5ff-18e7-4051-9d6e-12cc93eca35b\u0027)",
"presentationValues": [
{
"@odata.type": "#microsoft.graph.groupPolicyPresentationValueList",
"values": [
{
"name": "*",
"value": null
}
],
"presentation@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u00273705e5ff-18e7-4051-9d6e-12cc93eca35b\u0027)/presentations(\u002715374e33-8b97-4d41-8253-9b90ce9bc645\u0027)"
}
],
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027c12cd0b7-a46f-4cc5-8dbd-1ce17d69c702\u0027)",
"enabled": false
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u002763db8dde-bcaf-49de-8964-1f68371c4d2c\u0027)",
"enabled": false
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027b0689b0a-b725-4070-a5bf-32be09e495cf\u0027)",
"enabled": false
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u002784c82f32-04f7-4074-a5c4-3544a98208b8\u0027)",
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u002708c228ef-25e3-45b2-9afe-47bb2f2ab7eb\u0027)",
"presentationValues": [
{
"@odata.type": "#microsoft.graph.groupPolicyPresentationValueText",
"value": "2",
"presentation@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u002708c228ef-25e3-45b2-9afe-47bb2f2ab7eb\u0027)/presentations(\u0027cb2eb670-db0b-4efc-97b3-36b7e13e576e\u0027)"
}
],
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u00279777a6fc-7311-4842-a2ae-5b34e4c6b94a\u0027)",
"presentationValues": [
{
"@odata.type": "#microsoft.graph.groupPolicyPresentationValueList",
"values": [
{
"name": "[*.]didac.no",
"value": null
},
{
"name": "clikc.wcoomd.org",
"value": null
},
{
"name": "norsktollerforbund.sharepoint.com",
"value": null
},
{
"name": "https://p360pd.toll.no",
"value": null
},
{
"name": "https://regnskap-agrdra.dfo.no",
"value": null
}
],
"presentation@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u00279777a6fc-7311-4842-a2ae-5b34e4c6b94a\u0027)/presentations(\u0027cf6985ea-33cb-4bb8-bf10-02c1aa49f35f\u0027)"
}
],
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u00273e3ef429-ba9c-4bf5-9c54-5caf3aac9831\u0027)",
"presentationValues": [
{
"@odata.type": "#microsoft.graph.groupPolicyPresentationValueText",
"value": "https://www.google.com",
"presentation@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u00273e3ef429-ba9c-4bf5-9c54-5caf3aac9831\u0027)/presentations(\u0027bb6876d7-90c5-4281-a9a2-7154ed9afd79\u0027)"
}
],
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u002746436297-0d1e-45db-be13-5e3fccff84af\u0027)",
"presentationValues": [
{
"@odata.type": "#microsoft.graph.groupPolicyPresentationValueText",
"value": "2",
"presentation@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u002746436297-0d1e-45db-be13-5e3fccff84af\u0027)/presentations(\u0027d00346f1-de43-4797-bf2e-fbe1db8acbc6\u0027)"
}
],
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u00277d66e7bd-0a01-4f66-8d76-690a58276985\u0027)",
"enabled": false
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027df68228c-1238-41da-975a-71ce2b241b12\u0027)",
"presentationValues": [
{
"@odata.type": "#microsoft.graph.groupPolicyPresentationValueText",
"value": "2",
"presentation@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027df68228c-1238-41da-975a-71ce2b241b12\u0027)/presentations(\u0027a0c5718b-5463-42a1-8888-18d2dea6622c\u0027)"
}
],
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027bcbc275c-0c2e-41ee-826e-77a0c8ef3dfc\u0027)",
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027732b39c3-e2c5-4c6c-a6a3-9b4fcdde3feb\u0027)",
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u002732cb2ceb-a08a-4406-8977-a1a124c2de42\u0027)",
"presentationValues": [
{
"@odata.type": "#microsoft.graph.groupPolicyPresentationValueList",
"values": [
{
"name": "com.microsoft.browsercore",
"value": null
}
],
"presentation@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u002732cb2ceb-a08a-4406-8977-a1a124c2de42\u0027)/presentations(\u0027f849b343-4761-4326-ae50-9dc1eeb87383\u0027)"
}
],
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u00270a125ca8-f0eb-4914-83ee-a41ee85a0e2b\u0027)",
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027c4282b30-71ac-4c45-b4e3-b317211fd5e8\u0027)",
"presentationValues": [
{
"@odata.type": "#microsoft.graph.groupPolicyPresentationValueText",
"value": "0",
"presentation@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027c4282b30-71ac-4c45-b4e3-b317211fd5e8\u0027)/presentations(\u00274f5c7fa8-a533-48e5-a0ba-bc4f5e9dbb16\u0027)"
}
],
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u00271c484cb4-c95c-45ee-aae6-cfaafcae6d61\u0027)",
"enabled": false
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027124c9a03-7378-44b6-914b-e00f63dd399b\u0027)",
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u002709d328bc-a4a6-414d-abe3-ed453ca82172\u0027)",
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027fb18f15f-d16e-45f9-a79c-efa4da12203f\u0027)",
"presentationValues": [
{
"@odata.type": "#microsoft.graph.groupPolicyPresentationValueText",
"value": "2",
"presentation@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027fb18f15f-d16e-45f9-a79c-efa4da12203f\u0027)/presentations(\u0027e3bb6241-cdd2-4dec-a276-e6898a2725bd\u0027)"
}
],
"enabled": true
},
{
"definition@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027d4e64503-0338-4cae-9712-efec0461b8fe\u0027)",
"presentationValues": [
{
"@odata.type": "#microsoft.graph.groupPolicyPresentationValueText",
"value": "4",
"presentation@odata.bind": "https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions(\u0027d4e64503-0338-4cae-9712-efec0461b8fe\u0027)/presentations(\u0027c67624ce-2404-4740-a7d1-da572d847231\u0027)"
}
],
"enabled": true
}
]
我尝试过的内容适用于其他 .json 文件,但不适用于以“[”开头并以“]”结尾的文件。以下:
$input = Get-Content -Path $jsonFileContents | ConvertFrom-Json
给出输出(命名为 $input):
definition@odata.bind enabled
--------------------- -------
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('670ed8e1-25f4-4c24-b9ea-04b861a4566f') False
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('3705e5ff-18e7-4051-9d6e-12cc93eca35b') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('c12cd0b7-a46f-4cc5-8dbd-1ce17d69c702') False
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('63db8dde-bcaf-49de-8964-1f68371c4d2c') False
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('b0689b0a-b725-4070-a5bf-32be09e495cf') False
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('84c82f32-04f7-4074-a5c4-3544a98208b8') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('08c228ef-25e3-45b2-9afe-47bb2f2ab7eb') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('9777a6fc-7311-4842-a2ae-5b34e4c6b94a') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('3e3ef429-ba9c-4bf5-9c54-5caf3aac9831') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('46436297-0d1e-45db-be13-5e3fccff84af') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('7d66e7bd-0a01-4f66-8d76-690a58276985') False
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('df68228c-1238-41da-975a-71ce2b241b12') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('bcbc275c-0c2e-41ee-826e-77a0c8ef3dfc') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('732b39c3-e2c5-4c6c-a6a3-9b4fcdde3feb') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('32cb2ceb-a08a-4406-8977-a1a124c2de42') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('0a125ca8-f0eb-4914-83ee-a41ee85a0e2b') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('c4282b30-71ac-4c45-b4e3-b317211fd5e8') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('1c484cb4-c95c-45ee-aae6-cfaafcae6d61') False
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('124c9a03-7378-44b6-914b-e00f63dd399b') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('09d328bc-a4a6-414d-abe3-ed453ca82172') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('fb18f15f-d16e-45f9-a79c-efa4da12203f') True
https://graph.microsoft.com/beta/deviceManagement/groupPolicyDefinitions('d4e64503-0338-4cae-9712-efec0461b8fe') True
因此丢失了很多信息。
使用其他类型的文件(以 { .. } 开头和结尾)我使用了以下文件,其中Flatten-PsCustomObject
来自上面的 git-link
$input = Get-Content -Path $inputFile | ConvertFrom-Json
Flatten-PsCustomObject 'someString' $input
这完美地工作。我在做什么错/如何处理 [ ... ] 文件?感谢您对此事的意见!