0

enter image description hereI have a code which gives me below output.

 assigned_to
@{display_value=Raju Mishra link=https://googleprod.service-now.com/api/now/v1/table/sys_user/6486d149db70ee40db88b9d10f961969

}

Desired Output

Username
Raju Mishra

With below command, I am getting below output.

Select @{name="Username";Expression={($_.assigned_to -split '=')[1] -join ' ' }}

The Output which I am getting with it is:

Username                                                                                                                            
Raju Mishra; link
GURU SINGH
  • 149
  • 7
  • 2
    If that command you;re using is retrieving an object you'd be better getting the correct value with the command instead of trying to split the object as a string afterwards. – Scepticalist Jul 29 '20 at 07:18
  • could you provide me the command to do it. I am not too good with Powershell – GURU SINGH Jul 29 '20 at 07:31
  • 1
    I don;t know what command you;re using.... – Scepticalist Jul 29 '20 at 07:35
  • @GURUSINGH - *I have a command which gives me below output* - add the command to your question. – Lieven Keersmaekers Jul 29 '20 at 07:42
  • @ Lieven Keersmaekers Select @{name="Username";Expression={($_.assigned_to -split '=')[1] -join ' ' }}. – GURU SINGH Jul 29 '20 at 07:44
  • @Scepticalist Please find the command -- Select @{name="Username";Expression={($_.assigned_to -split '=')[1] -join ' ' }} – GURU SINGH Jul 29 '20 at 07:54
  • What does `(... -First 1).assigned_to.GetType()` Return? What is the output of `(... -First 1).assigned_to | gm`? – Lieven Keersmaekers Jul 29 '20 at 08:44
  • Thanks @LievenKeersmaekers. I changed the bit in my code and it works. – GURU SINGH Jul 29 '20 at 09:28
  • No problem offcourse but what did you have to change :) – Lieven Keersmaekers Jul 29 '20 at 09:29
  • Update your question with the code from your image. – Daniel Björk Jul 29 '20 at 09:30
  • I'm coming to this late, and I understand you're already past the issue. Hope you don't mind my comment. I think the assigned_to property may itself be a rich object, not a string. `-Split` may have implicitly converted to a string, maybe explaining the hash like object syntax from your question. So, I wonder if a more simple property expression like: `@{Name = "Username"; Expression= { $_.assigned_to.display_value }` would've worked? Assuming `.display_value` is a string. – Steven Jul 29 '20 at 11:18

0 Answers0