maarten
February 25, 2020, 6:54am
1
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.
Olaf
February 25, 2020, 7:12am
2
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
maarten
February 25, 2020, 8:20am
3
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
maarten
February 25, 2020, 8:50am
4
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
$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
maarten
February 25, 2020, 9:00am
6
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”
[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]
}
}
Olaf
February 25, 2020, 9:06am
8
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 .
riedyw
February 27, 2020, 2:13pm
9
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.
get-content .\longtext.txt | foreach-object {
if ($_ -match '("{.+}" "{.+}")') {
$matches[1]
}
}
I hope this helps. Good luck in whatever you are doing.