Instead of initiating several questions for the same (or at least very similar) question, try to understand the (already existing) answers. A good practice to come to a conclusion of a specific question is to:
- create a Minimal, Reproducible Example (for this, take all the words of the concept literal)
- Show what you receive as an actual result of your attempt to resolve the issue
- Show what you would expect as a result to your question
(see also how to ask)
As for the question with a bounty, powershell parse Json file with \ and wildcard in the key name, it would only be fair to upvote or accepted the answers from the others instead of your own answer (which only covers a small part of the question).
Specific to this issue
(I actually suspect a bug here.)
For this I have taken the full Json example from your question powershell parse the Json after ConvertTo-Json
$Json = @' ...
{
"id": "/subscriptions/fcxxxx7/resourceGroups/xxxxxx/providers/Microsoft.Web/sites/xxxx/workflows/Test_email",
"name": "xxxxxxxxx/Test_email",
"type": "Microsoft.Web/sites/workflows",
"kind": "Stateful",
"location": "East Asia",
"properties": {
"files": {
"Test_email/workflow.json": {
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Send_an_email_from_a_shared_mailbox_(V2)": {
"inputs": {
"host": {
"connection": {
"referenceName": "My new value for: TheValueIwant"
}
},
"method": "post",
"path": "/v2/SharedMailbox/Mail"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {}
},
"kind": "Stateful"
}
}
}
}
'@
$ChangeInfo = ConvertFrom-Json $Json
Once converted from json, using ConvertFrom-Json or implied by using Invoke-RestMethod, the result is a PowerShell object which is completely independent from (and unrelated to) Json. See also this answer from mklement0.
Accessing
Normally, Member-Access enumeration, offers you a convenient way to get the concerned values:
$ChangeInfo.changes.item.path
But in this specific case there appears to be a bug where the specific member name item
is apparently internally used for the iteration. see: Can't enumerate item
member #19570
.
In other words, you will need to enumerate this specific member "manually":
$CommitInfo.changes.foreach{ $_.item }.path
/pipeline
/pipeline/PL_xxxx_START.json
/trigger
/trigger/TRIGGER_xxxx_WKLY.json
Filtering
This mean if yo want e.g filter a url
of an item
on a specific path you will need to do something like this:
$CommitInfo.changes.foreach{ $_.item }.where{ $_.path -eq '/pipeline/PL_xxxx_START.json' }.url
https://dev.azure.com/xxxx
And if you have multiple paths to filter on you might take advantage of this common comparison feature:
When the input is a collection, the operator returns the elements of the collection that match the right-hand value of the expression.
$PathFilter =
'/pipeline/PL_xxxx_START.json',
'/trigger/TRIGGER_xxxx_WKLY.json'
$CommitInfo.changes.foreach{ $_.item }.where{ $PathFilter -eq $_.path }.objectId
dd6d17aa11bexxxxx10aeedb
13e6685cddxxxxd9e159
Changing
To change a specific path
within this concerned item
property, e.g. the 3rd (the array is zero based):
$CommitInfo.changes.foreach{ $_.item }[2].path = 'Another path'
$CommitInfo |ConvertTo-Json -Depth 10
Results:
{
"changeCounts": {
"Edit": 4
},
"changes": [
{
"item": {
"objectId": "7e852adxxxxxxxba3792",
"originalObjectId": "c77692938423cxxxx912bf7",
"gitObjectType": "tree",
"commitId": "a73b19232650xxxxx1b6d4a6c969",
"path": "/pipeline",
"isFolder": true,
"url": "https://dev.azure.com/xxxx"
},
"changeType": "edit"
},
{
"item": {
"objectId": "dd6d17aa11bexxxxx10aeedb",
"originalObjectId": "98a11c2fe819xxxx089fc62e986",
"gitObjectType": "blob",
"commitId": "a73b19232650fcxxxxx6d4a6c969",
"path": "/pipeline/PL_xxxx_START.json",
"url": "https://dev.azure.com/xxxx"
},
"changeType": "edit"
},
{
"item": {
"objectId": "7b3cfd336cxxxxed652446",
"originalObjectId": "a67b91d65xxxx9c4605143",
"gitObjectType": "tree",
"commitId": "a73b19232650fcbxxxx4a6c969",
"path": "Another path",
"isFolder": true,
"url": "https://dev.azure.com/xxxx"
},
"changeType": "edit"
},
{
"item": {
"objectId": "13e6685cddxxxxd9e159",
"originalObjectId": "48d0cf833xxxx43064",
"gitObjectType": "blob",
"commitId": "a73b19232xxxx6d4a6c969",
"path": "/trigger/TRIGGER_xxxx_WKLY.json",
"url": "https://dev.azure.com/xxxx"
},
"changeType": "edit"
}
]
}