# Get substring

**URL:** <https://forums.powershell.org/t/get-substring/13863>\
**Category:** PowerShell Help\
**Created:** [February 25, 2020, 6:54am UTC](https://forums.powershell.org/t/get-substring/13863 "2020-02-25T06:54:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![maarten](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@maarten](https://forums.powershell.org/u/maarten)\
**Post date:** [February 25, 2020, 6:54am UTC](https://forums.powershell.org/t/get-substring/13863/1 "2020-02-25T06:54:25Z")

</div>

Can you help me?

For example, how do I get “{90150000-012B-040C-0000-0000000FF1CE}” “{D17A4D8B-29D2-4432-A08E-F89F965FDA60}” from the string

“C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\Oarpmany.exe /removereleaseinpatch” “{90150000-012B-040C-0000-0000000FF1CE}” “{D17A4D8B-29D2-4432-A08E-F89F965FDA60}” “1043” “0” or

“C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\Oarpmany.exe” /removereleaseinpatch “{90150000-012B-040C-0000-0000000FF1CE}” “{D17A4D8B-29D2-4432-A08E-F89F965FDA60}” “1043” “0”

etc.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 25, 2020, 7:12am UTC](https://forums.powershell.org/t/get-substring/13863/2 "2020-02-25T07:12:23Z")

</div>

What have you tried so far? Please show your code.

The simplest approach would be something like this:

```
$String = '"C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\Oarpmany.exe /removereleaseinpatch" "{90150000-012B-040C-0000-0000000FF1CE}" "{D17A4D8B-29D2-4432-A08E-F89F965FDA60}" "1043" "0"'
$String -match '"{.*}"'
$Matches
```

---

<div class="post-metadata">

**Author:** ![maarten](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@maarten](https://forums.powershell.org/u/maarten)\
**Post date:** [February 25, 2020, 8:20am UTC](https://forums.powershell.org/t/get-substring/13863/3 "2020-02-25T08:20:39Z")

</div>

I tried with split -match etc.

But the end result is

msiexec /x “{90150000-012B-0413-0000-0000000FF1CE}” MSIPATCHREMOVE={D17A4D8B-29D2-4432-A08E-F89F965FDA60}/qn REBOOT=REALLYSUPPRESS

---

<div class="post-metadata">

**Author:** ![maarten](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@maarten](https://forums.powershell.org/u/maarten)\
**Post date:** [February 25, 2020, 8:50am UTC](https://forums.powershell.org/t/get-substring/13863/4 "2020-02-25T08:50:40Z")

</div>

I craete this code, but it goes wrong on /removereleaseinpatch

(((Seach-InstalledSoftware -name “\*Skype”).UninstallString))

Output: “C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\Oarpmany.exe” /removereleaseinpatch “{90150000-012B-040C-0000-0000000FF1CE}” “{D17A4D8B-29D2-4432-A08E-F89F965FDA60}” “1043” “0”

$String -match ‘“{.\*}”’ \> $null

$A=($Matches[0]).split(" ")  
$b = “msiexec /x $($A[0]) MSIPATCHREMOVE=$($A[1]) /qn REBOOT=REALLYSUPPRESS”  
$B

---

<div class="post-metadata">

**Author:** ![sam-boutros](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/sam-boutros/32/5_2.png) [@sam-boutros](https://forums.powershell.org/u/sam-boutros)\
**Post date:** [February 25, 2020, 8:55am UTC](https://forums.powershell.org/t/get-substring/13863/5 "2020-02-25T08:55:39Z")

</div>

```
$myInput = @(
'"C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\Oarpmany.exe" /removereleaseinpatch" "{90150000-012B-040C-0000-0000000FF1CE}" "{D17A4D8B-29D2-4432-A08E-F89F965FDA60}" "1043" "0"' 
'"C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\Oarpmany.exe" /removereleaseinpatch" "{12345678-012B-040C-0000-0000000FF1CE}" "{abcdefgh-29D2-4432-A08E-F89F965FDA60}" "1043" "0"'
)

$myOutput = foreach ($Item in $myInput) { 
    [PSCustomObject]@{
        Guid1 = $Item.Split('{')[1].Split('}')[0]
        Guid2 = $Item.Split('{')[2].Split('}')[0]
    }
}

$myOutput | FT -a
```

```
Guid1 Guid2                               
----- -----                               
90150000-012B-040C-0000-0000000FF1CE D17A4D8B-29D2-4432-A08E-F89F965FDA60
12345678-012B-040C-0000-0000000FF1CE abcdefgh-29D2-4432-A08E-F89F965FDA60
```

I would point out here that the splitting in lines 8 and 9 is done via the braces {} and not the spaces or double-quotes

---

<div class="post-metadata">

**Author:** ![maarten](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@maarten](https://forums.powershell.org/u/maarten)\
**Post date:** [February 25, 2020, 9:00am UTC](https://forums.powershell.org/t/get-substring/13863/6 "2020-02-25T09:00:41Z")

</div>

Guy’s

Greate but the out-put from the function is:

((Seach-InstalledSoftware -name “\*Skype”).UninstallString))

Output: “C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\Oarpmany.exe” /removereleaseinpatch “{90150000-012B-040C-0000-0000000FF1CE}” “{D17A4D8B-29D2-4432-A08E-F89F965FDA60}” “1043” “0”

&nbsp;

---

<div class="post-metadata">

**Author:** ![sam-boutros](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/sam-boutros/32/5_2.png) [@sam-boutros](https://forums.powershell.org/u/sam-boutros)\
**Post date:** [February 25, 2020, 9:02am UTC](https://forums.powershell.org/t/get-substring/13863/7 "2020-02-25T09:02:51Z")

</div>

[quote quote=205953]Guy’s

Greate but the out-put is from an function

((Seach-InstalledSoftware -name “\*Skype”).UninstallString))

Output: “C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\Oarpmany.exe” /removereleaseinpatch “{90150000-012B-040C-0000-0000000FF1CE}” “{D17A4D8B-29D2-4432-A08E-F89F965FDA60}” “1043” “0”[/quote]

```
(((Seach-InstalledSoftware -name “*Skype”).UninstallString)) | foreach { 
    [PSCustomObject]@{
        Guid1 = $PSItem.Split('{')[1].Split('}')[0]
        Guid2 = $PSItem.Split('{')[2].Split('}')[0]
    }
}
```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 25, 2020, 9:06am UTC](https://forums.powershell.org/t/get-substring/13863/8 "2020-02-25T09:06:40Z")

</div>

OK. I assume you want to remove some installed software, right? There are several examples out there on the internet. You don’t have to re-invent the wheel. One good place to start your search will be the [PowershellGallery](https://www.powershellgallery.com/).

---

<div class="post-metadata">

**Author:** ![riedyw](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/riedyw/32/53_2.png) [@riedyw](https://forums.powershell.org/u/riedyw)\
**Post date:** [February 27, 2020, 2:13pm UTC](https://forums.powershell.org/t/get-substring/13863/9 "2020-02-27T14:13:21Z")

</div>

To answer your original question regarding getting the substring I think I have a solution for you. First I replaced your curly quotes with normal quotes $([char] 34) and saved the text to the file LongText.txt. Here is the command to pull just the substrings.

&nbsp;

```
get-content .\longtext.txt | foreach-object {
    if ($_ -match '("{.+}" "{.+}")') {
        $matches[1]
    }
}
```

I hope this helps. Good luck in whatever you are doing.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:30pm UTC](https://forums.powershell.org/t/get-substring/13863/10 "2024-05-16T20:30:38Z")

</div>


