Reputation:
Hello i have powershell command that looks like this.
$result = Add-SPOSiteScript -Title "Create customer tracking list" -Content $site_script -Description "Creates list for tracking customer contact information" | Out-String
And output like this
Id : xxx69add-xxd1-xx43-xxba-xxcd2fac8790
Title : Create customer tracking list
Description : Creates list for tracking customer contact information
Content : xxx
Version : 0
IsSiteScriptPackage : False
What I want to do is to take Id somehow from it but I don't know-how. I don't know how to output this as an array so i can use $result[0]
or any other way how to extract it.
Thanks for any help.
Upvotes: 0
Views: 162
Reputation: 174435
Out-String
turns all the input into a string, so not very useful here.
Either enclose the expression in parentheses and reference the Id
parameter with the .
member access operator:
$result = (Add-SPOSiteScript -Title "Create customer tracking list" -Content $site_script -Description "Creates list for tracking customer contact information").Id
Or grab the Id
property value with Select-Object
:
$result = Add-SPOSiteScript -Title "Create customer tracking list" -Content $site_script -Description "Creates list for tracking customer contact information" |Select-Object -ExpandProperty Id
... or by using ForEach-Object
member invocation:
$result = Add-SPOSiteScript -Title "Create customer tracking list" -Content $site_script -Description "Creates list for tracking customer contact information" |ForEach-Object Id
Upvotes: 1