Split Array

Hi,

i want to split the above result into to parts an advise to two variables:

Sadly I have no idea how to do it.

PS C:\Users\admin\Desktop> $vApplictaionDetect

"C:\Program Files (x86)\InstallShield Installation Information\{99B87886-CD77-4466-8002-96FD09B9B3DE}\setup.exe" -runfromtemp -l0x0409  UNINSTALL -removeonly

The result should look like that:

$Variable1 = "C:\Program Files (x86)\InstallShield Installation Information\{99B87886-CD77-4466-8002-96FD09B9B3DE}\setup.exe"

$Variable2 = -runfromtemp -l0x0409  UNINSTALL -removeonly

Sad

 -runfromtemp -l0x0409  UNINSTALL -re

moveonly


  • Edited by Strahle_fz 21 hours 59 minutes ago edit
September 2nd, 2015 5:08am

Hi Strahle,

you can use a -split to split a string and Select-Object to select parts of it:

$vApplicationDetect = '"C:\Program Files (x86)\InstallShield Installation Information\{99B87886-CD77-4466-8002-96FD09B9B3DE}\setup.exe" -runfromtemp -l0x0409 UNINSTALL -removeonly'
$Variable1 = $vApplicationDetect -split '"' | Select-Object -First 1 -Skip 1
$Variable2 = ($vApplicationDetect -split '"' | Select-Object -Last 1).Trim()
$Variable1
$Variable2

Cheers,
Fred

Free Windows Admin Tool Kit Click here and download it now
September 2nd, 2015 5:40am

Using -match:

$text = '"C:\Program Files (x86)\InstallShield Installation Information\{99B87886-CD77-4466-8002-96FD09B9B3DE}\setup.exe" -runfromtemp -l0x0409  UNINSTALL -removeonly'

if ($text -match '(.+?)\s+(-runfromtemp.+)\s*')
  { $Variable1,$Variable2 = $matches[1,2] }

$Variable1
$Variable2

"C:\Program Files (x86)\InstallShield Installation Information\{99B87886-CD77-4466-8002-96FD09B9B3DE}\setu
p.exe"
-runfromtemp -l0x0409  UNINSTALL -removeonly

September 2nd, 2015 7:10am

This works for me:
$d = '-runfromtemp'
$s = '"C:\Program Files (x86)\InstallShield Installation Information\{99B87886-CD77-4466-8002-96FD09B9B3DE}\setup.exe" -runfromtemp -l0x0409  UNINSTALL -removeonly'
$a = $s -split $d,2
$Variable1 = $a[0].Trim()
$Variable2 = $d + $a[1]

Free Windows Admin Tool Kit Click here and download it now
September 2nd, 2015 12:37pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics