How to get the item under an object (eg lasttokenissued.dateissued for use in PowerShell CLI script

Hi guys

Here's a snippet of a script I've got working fine for datelastlogin:

	(./gc.exe users get --expand="dateLastLogin" $($_.id) | ConvertFrom-Json) | Select-Object id, name, dateLastLogin, state| 
		ForEach-Object {
			Write-Host "$($_.name),$($_.dateLastLogin),$userLicense,$($_.state)"
						}

I"m wanting to enhance that to expand on the lasttokenissued object and bring in the dateissued item from that but I can't get my head around how to do something like lasttokenissued.dateissued so that I have $($_.dateissued) available in my Write-Host line.

Any pointers?

EDIT: I raised a case with Genesys support. This API doesn't appear to be returning that data, and I hate when stuff doesn't work as documented.

Since it should be cast as a nested PSObject, it should be as simple as

(./gc.exe users get --expand="dateLastLogin,lastTokenIssued" $($_.id) | ConvertFrom-Json) | Select-Object id, name, dateLastLogin, state| 
		ForEach-Object {
			Write-Host "$($_.name),$($_.dateLastLogin),$userLicense,$($_.state),$($_.lastTokenIssued.dateIssued)"
						}

I'm using straight PowerShell scripting, not the PS EXE, but in my testing, I wasn't even getting the lastTokenIssued property back when calling the /api/v2/users API even with lastTokenIssued as an expand property. I think there's either a bug in the API, or bad documentation on requirements to get this property back when calling it.

Thanks Paul, I'll be curious to see how Genesys respond to you.

Support got back to me. Apparently "lastTokenIssued" should be all lowercase, so "lasttokenissued". I'm declaring that a bug, rather than a documentation issue, because the return property IS in camel case as-documented.

Try this. PowerShell isn't case-sensitive with property names, thankfully.

(./gc.exe users get --expand="dateLastLogin,lasttokenissued" $($_.id) | ConvertFrom-Json) | Select-Object id, name, dateLastLogin, state| 
		ForEach-Object {
			Write-Host "$($_.name),$($_.dateLastLogin),$userLicense,$($_.state),$($_.lastTokenIssued.dateIssued)"
						}

Hello,

As a note, the "lasttokenissued" value (in lowercase), used in expand parameter, is documented in the Request Parameters (under API Request section) of the GET /api/v2/users endpoint.

Regards,

Thanks Jerome - consistency would help old people like me :slight_smile:

This does work fine now as long as you consider the difference in case.