r/PowerShell • u/Arnoc_ • Dec 11 '25
Powershell - Extract Values from Singleline Value
Our Help Desk Service at work has an API and a PowerShell module for it to make calling the API easy.
Goal want to accomplish is to pull information from New Hire Tickets directly into script we have for creating accounts, so that there is no potential for user error from our Help Desk tech side manually entering in account details to a ticket.
I can call up the details of a ticket via powershell, and it returns a single line value that's formatted as such:
custom_fields
-------------
@{first_name=Value; middle_name_not_required=; last_name=' title; ...
eventually ending in a } of course.
I don't know PowerShell well enough to know the correct names of stuff to know how to formulate my question properly.
But from what I can tell, that is a single-line output. I'd like it to be stored so I could call a specific value from it, such as say: $customVariable.first_name to get the first_name value from it.
I've tried for instance to store the contents from the ticket in a variable named $custom
Then tried to do:
$string = $custom.Split(";")
But that returns:
Method invocation failed because [Selected.System.Management.Automation.PSCustomObject] does not contain a method named 'Split'.
Any suggestions on what to do?
3
u/surfingoldelephant Dec 11 '25
$customis a custom object emitted bySelect-Object(based on theSelectedin error message).It has a
custom_fieldsproperty with a value that's also a custom object (based on how it's rendered for display). It's not a JSON string as others have commented. Confirm this with:So to retrieve the value of
first_namefrom the nested custom object:Or change your
Select-Objectcall to use-ExpandProperty. Something like this (replace...with whatever you're passing toSelect-Object):4
u/AdeelAutomates Dec 11 '25 edited Dec 11 '25
It is an object all the way through. Lets look at the output you shared that $custom is storing:
custom_fields is inside $custom and it's indicating a key that contains the the first_name, etc as it's values.
$custom.custom_fieldsOutput this and its possible that the first_name and all that is already objects as well. So you can use the following to get each field's value:
@{ key = value; key2 = value2 } is the format of objects in PowerShell.
If it was JSON you would see quotes, colons and no @ sign like so as your output:
so nothing to split. It's all ready to be used :) just drill down each value.
1
u/goldenfrogs17 Dec 11 '25
when is $custom assigned a string value? or explicitly cast [string] ?
1
u/throwaway09563 Dec 11 '25
Looks like JSON, which I would expect from an API call these days.
You might try piping the result to ConvertFrom-JSON and see if it parses it out a little nicer for you.
-4
u/an_harmonica Dec 11 '25
You would need to convert that line to a string. Split is a string object method. Same with Replace, trim, etc.