0

So I'm able to connect to an API and generate items based on a template from that data. But what is stumping me is the ability to get a child JSON element of one that contains a colon.

For example the code below is what I have currently:

$parentPath = Get-Item -Path "master:\" -ID "{2EDC48D0-6134-48DB-B103-DE6F4103B8EE}"
$Faculty_TemplateID = "{E2524ACD-C438-4263-9088-3EFBACB8CD9E}"
$items = Invoke-RestMethod -uri "*API URL*"

foreach($f in $items){
  $faculty_firstName = $f.leadership_checkbox.first_name
  $faculty_lastName = $f.leadership_checkbox.last_name
  $faculty_position = $f.leadership_checkbox.title

  #creating of the item
  $faculty_item = New-Item -Parent $parentPath -Name $faculty_title -ItemType $Faculty_TemplateID

  #setting field values on the created items
  $faculty_item.Editing.BeginEdit()
    $faculty_item.Fields["Title"].Value = $faculty_title
    $faculty_item.Fields["First Name"].Value = $faculty_firstName
    $faculty_item.Fields["Last Name"].Value = $faculty_lastName
  $faculty_item.Editing.EndEdit()
}

Where the code is setting the variables, I'd like to add another one

$faculty_firstName = $f.leadership_checkbox.first_name
$faculty_lastName = $f.leadership_checkbox.last_name
$faculty_position = $f.leadership_checkbox.title
#NEW ONE
$faculty_info = $f.leadership_checkbox.wp:someImportantInfo

Powershell throws an "Unexpected Token" error when I try to do this like normal. I've tried things like Join-Path but nothing I've found seems to be working. Any Ideas?

2

The colon is invalid PowerShell syntax.

For cases where the field name contains a space you can simply enclose it with quotes.

$item."Field Name"
$item.'Field Name"
1
  • Worked like a charm! Thank you!
    – jonwa
    Nov 9 '20 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.