0

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.

2

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.