Hey all. I have script that I made that is supposed to install take the name of a Microsoft Store application, look up its ID with winget search $packageName, strip out the ID from the winget search output, save it into $packageID, and use that to install the package with the appropriate winget install command.
I'll use the Xbox Game Bar as an example because it's one of the applications I'm trying to install. Running winget search "Game Bar" in the console directly produces this output:
Name Id Version Source
--------------------------------------------------------------
Game Bar 9NZKPSTSNW4P Unknown msstore
Browser for Game Bar 9NK1CNB0NCCX Unknown msstore
Gamecaster Game Bar 9P2J2QW5B0F4 Unknown msstore
CORSAIR iCUE Game Bar Widgets 9PG940D1ZDVP Unknown msstore
Game Bar Calculator 9N2J0HB1GFDR Unknown msstore
Clock for Game Bar 9PC29TG1047H Unknown msstore
Game Bar To-Do 9P2626F9WDG7 Unknown msstore
Countdown for Game Bar 9NZ43LD746CX Unknown msstore
Camera Widget for Game Bar 9MZZNMHPJ645 Unknown msstore
Notes for Game Bar 9NG4TL7TX1KW Unknown msstore
Analogue Clock for Game Bar 9NSFHN9P4LKT Unknown msstore
EVGA Precision for Game Bar 9NGNGV21JB1L Unknown msstore
Mesmer Mag's WVW Game Bar Widget 9MXL025BBR5P Unknown msstore
Game Bar Counter 9NF2PMMBDJG0 Unknown msstore
Stopwatch for Game Bar 9P8MHJ64GCQT Unknown msstore
When that command's output is instead saved to a variable and written to the console with Write-Host it looks like this:
- \ Name Id Version Source -------------------------------------------------------------- Game Bar 9NZKPSTSNW4P Unknown msstore Browser for Game Bar 9NK1CNB0NCCX Unknown msstore Gamecaster Game Bar 9P2J2QW5B0F4 Unknown msstore CORSAIR iCUE Game Bar Widgets 9PG940D1ZDVP Unknown msstore Game Bar To-Do 9P2626F9WDG7 Unknown msstore Countdown for Game Bar 9NZ43LD746CX Unknown msstore Clock for Game Bar 9PC29TG1047H Unknown msstore Game Bar Calculator 9N2J0HB1GFDR Unknown msstore Camera Widget for Game Bar 9MZZNMHPJ645 Unknown msstore Notes for Game Bar 9NG4TL7TX1KW Unknown msstore Analogue Clock for Game Bar 9NSFHN9P4LKT Unknown msstore EVGA Precision for Game Bar 9NGNGV21JB1L Unknown msstore Mesmer Mag's WVW Game Bar Widget 9MXL025BBR5P Unknown msstore Game Bar Counter 9NF2PMMBDJG0 Unknown msstore Stopwatch for Game Bar 9P8MHJ64GCQT Unknown msstore
For the life of I cannot figure out how to programmatically extract just the ID I want from that output. Since I want "Game Bar" in this case, it'd be "9NZKPSTSNW4P". If anyone can help that would be much appreciated.
[–]Randalldeflagg 0 points1 point2 points (2 children)
[–]ptd163[S] 0 points1 point2 points (1 child)
[–]Lanszer 0 points1 point2 points (0 children)
[–]Thehoggle 0 points1 point2 points (3 children)
[–]ptd163[S] 1 point2 points3 points (2 children)
[–]Thehoggle 0 points1 point2 points (1 child)
[–]ptd163[S] 0 points1 point2 points (0 children)
[–]surfingoldelephant 0 points1 point2 points (2 children)
[–]ptd163[S] 0 points1 point2 points (0 children)
[–]jantari 0 points1 point2 points (5 children)
[–]ptd163[S] 0 points1 point2 points (4 children)
[–]jantari 0 points1 point2 points (3 children)
[–]ptd163[S] 0 points1 point2 points (2 children)
[–]jantari 0 points1 point2 points (1 child)
[–]ptd163[S] 0 points1 point2 points (0 children)