Launching Modern Applications from the Command Line

Fri, Oct 30, 2015 2-minute read

We had an interesting discussion at work the other day about how to launch modern Windows applications from the command line.

There are a few solutions out there (Tome’s is close), although few of them are happy with their results :)

Many of them rely on protocol handlers (i.e.: “start bingnews://”), but that means memorizing a bunch of protocol handler prefixes.

Tome’s blog mentions the Get-AppxPackage cmdlet – the real workhorse of a proper solution.

Modern applications are placed in Appx packages. These packages may contain one or more applications. If an AppxPackage contains several applications, these will be listed in its package manifest – which you can retrieve through Get-AppxPackageManifest. The manifest is XML, which PowerShell’s XML support makes crazy easy to navigate.

Here’s an example of getting all of the modern applications that you can launch – place it in Get-AppxPackageEx.ps1:

[CmdletBinding()]
param($Name = "*")
foreach($package in Get-AppxPackage)
{
    foreach($appId in ($package | Get-AppxPackageManifest).Package.Applications.Application.Id)
    {
        if(($package.Name -like $Name) -or ($appId -like $Name))
        {
            "$($package.PackageFamilyName)!$appId"
        }
    }
}

There’s an example of getting all the apps you might want to launch. When it comes to launching one, the secret is to use the Shell handler to do it. Here’s a script that accomplishes it:

[CmdletBinding(SupportsShouldProcess)]
[Alias("StartApp")]
param($Name)
foreach($package in Get-AppxPackage)
{
    foreach($appId in ($package | Get-AppxPackageManifest).Package.Applications.Application.Id)
    {
        if(($package.Name -like $Name) -or ($appId -like $Name))
        {
            $commandLine = "shell:AppsFolder\$($package.PackageFamilyName)!$appId"
            if($PSCmdlet.ShouldProcess($commandLine))
            {
                start $commandLine
            }
        }
    }
}

Demo:

204 [C:\temp]
>> Start-AppxPackage *twitter* -whatif
What if: Performing the operation "Start-AppxPackage.ps1" on target "shell:AppsFolder\9E2F88E3.Twitter_wgeqdkkx372wm!App".