1

I wanna put all values after equal to (=) sign separated by colon (:) from below "passPercent" variable into a array using PowerShell script. Meaning array[0]=PROCESSING, array[1]=100, array[2]=75 and so on. How to do it?

$passPercent=PROCESSING:100.0:75:0:null:null:40:/#/app/projects/8a80808a69c899f10169c8a0d0610005/jobs/8a80808a69c899f10169c8a0da020079/runs/8a8080f169d28d430169d36a41090346:Bugs Logged = 0 Bugs Reopened = 0 Bugs Closed = 0 Total Bugs = 0

i did try this expression: $array = $passPercent | ConvertFrom-Json but was showing this error ConvertFrom-Json : Invalid JSON primitive: PROCESSING.

1 Answer 1

0

Use the Split Method:

$array =  $passPercent.Split(":")

enter image description here

6
  • it just store result into array by separating colon (:) like below array = PROCESSING 100.0 75 0 null null 42 /#/app/projects/8a80808a69c899f10169c8a0d0610005/jobs/8a80808a69c899f10169c8a0da020079/runs/8a8080f169d28d430169d4d858070494 Bugs Logged = 0 Bugs Reopened = 0 Bugs Closed = 0 Total Bugs = 0 i wanna store them array[0]=PROCESSING, array[1]=100 like we do other languages like shell-script Mar 31, 2019 at 17:48
  • This does it. I don't see what the problem is.
    – harrymc
    Mar 31, 2019 at 17:53
  • i wanna put those values in below expression Write-Host "Status =" "${array[0]}" " Success Percent =" "${array[1]}" " Total Tests =" "${array[2]}" " Time Taken =" "${array[4]}" " Run =" "${array[5]}" Mar 31, 2019 at 18:01
  • Your syntax is not PowerShell. You need something like Write-Host "Status =" , $array[0], " Success Percent =" , $array[1], " Total Tests =", $array[2].
    – harrymc
    Mar 31, 2019 at 18:13
  • thanks man, this is actually my first powershell script. that's why facing just a little difficulty with syntax and commands. Mar 31, 2019 at 18:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .