I am new to Powershell and I am trying to write a script. In that, I have an array $spCreated.
Its variable type is:
- Name: Object[]
- BaseType: System.Array
The $spCreated contains the value below:
[
{
"accountEnabled": "True",
"addIns": [],
"alternativeNames": [],
"appDisplayName": "testSP4",
"appId": "abc1234-abc1234-abc1234-abc1234-abc1234",
"appOwnerTenantId": "",
"appRoleAssignmentRequired": false,
"appRoles": [],
"applicationTemplateId": null,
"deletionTimestamp": null,
"displayName": "testSP4",
"errorUrl": null,
"homepage": null,
"informationalUrls": {
"marketing": null,
"privacy": null,
"support": null,
"termsOfService": null
},
"keyCredentials": [],
"logoutUrl": null,
"notificationEmailAddresses": [],
"oauth2Permissions": [
{
"adminConsentDescription": "text",
"adminConsentDisplayName": "Access testSP4",
"id": "ab123-ab123-ab123-ab123-ab123",
"isEnabled": true,
"type": "User",
"userConsentDescription": "Allow the application to access testSP4 on your behalf.",
"userConsentDisplayName": "Access testSP4",
"value": "user_impersonation"
}
],
"objectId": "abc1234-abc1234-abc1234-abc1234-abc1234",
"servicePrincipalType": "Application",
"signInAudience": "AzureADMyOrg",
"tags": [],
"tokenEncryptionKeyId": null
}
]
How can I get the value of objectId in a string variable?
I have tried the commands:
$z = $spCreated-match 'objectId'
$b = $z.Substring(15, $z.Length-1)
But it returns (with the quotes and comma)
"abc1234-abc1234-abc1234-abc1234-abc1234",
I just want abc1234-abc1234-abc1234-abc1234-abc1234
as a string.
Can I please get help on this? Thanks