locked
Accesing Metro via PowerShell

    Question

  • Is there a way to access the metro apps via powerShell? Would be fun to write a script to get a list of metro apps, or get information on a specific app, perhaps the ability to uninstall an app...etc
    Jeffrey S. Patton Assistant Director of IT School of Engineering Computing Services University of Kansas 1520 West 15th Street Lawrence, KS. 66045-7621 | http://patton-tech.com
    Wednesday, September 14, 2011 9:23 PM

Answers

  • Hi Jeffrey,

    First thing you'll want to run in powershell is "get-help appx".  You'll get the list of commands.

    Here are some handy questions and answers:

    How do I install a package?

    You can use any cases that are easy for you to type since PowerShell cmd-lets are case insensitive. Actually, with PowerShell, just typing add-app and hit Tab should autocomplete the right cmd-let!

    Add-AppXPackage c:\MyPackage.appx


    How can I see all the pacakages installed?

    We have a cmd-let for inventory with Get-AppxPackage.
    Get-AppxPackage

    PowerShell can pipe the results into filters like this for finding certain packages:
    Get-AppxPackage | Where-Object {$_.Name -like "*wwa*" }

    Get tired of typing? Too hard to see a big text list? Send it to PowerShell Grid-View and you get a UI for inventory with search!
    Get-AppxPackage  Out-GridView

    With variables, I can even just get a quick count:
    $packages = Get-AppxPackage
    $packages.Count

    How do I remove a package?

    Removing an AppX package needs the package moniker. You can use variables again and inventory to help:
    $toRemove = Get-AppxPackage | Where-Object {$_.Name -like "*wwa*" }
    Remove-AppxPackage $toRemove.PackageMoniker

    So Cool, What else can I do with PowerShell?

    How about sorting and getting a customized table of inventory with just Package Name and Install location:
    Get-AppxPackage  | Sort-Object Name | Format-Table Name,InstallLocation -Auto

    WOW, with PowerShell you can even take inventory and generate an HTML file:
    Get-AppxPackage | ConvertTo-Html | Set-Content temp.html

    Since PowerShell knows how to navigate XML natively, you can even navigate the Package Manifest with PowerShell. Here is getting the App ID from an app you searched for!
    $xml = Get-AppxPackage | Where-Object {$_.Name -like "*wwa*" } | Get-AppxPackageManifest
    $xml.Package.Applications.Application.Id

    How about navigating the event log to debug problems?

    One of the most common things that everyone is looking for is event logs when things go wrong. With PowerShell, not only do you get better error messages directly from the AppX deployment engine, you can easily query for the last 10 ETW messages from the deployment engine!
    Get-WinEvent -logname Microsoft-Windows-appx* | Select-Object -last 10 | Format-List -Property Message

     

    Thursday, September 15, 2011 12:11 AM
    Moderator

All replies

  • Hi Jeffrey,

    First thing you'll want to run in powershell is "get-help appx".  You'll get the list of commands.

    Here are some handy questions and answers:

    How do I install a package?

    You can use any cases that are easy for you to type since PowerShell cmd-lets are case insensitive. Actually, with PowerShell, just typing add-app and hit Tab should autocomplete the right cmd-let!

    Add-AppXPackage c:\MyPackage.appx


    How can I see all the pacakages installed?

    We have a cmd-let for inventory with Get-AppxPackage.
    Get-AppxPackage

    PowerShell can pipe the results into filters like this for finding certain packages:
    Get-AppxPackage | Where-Object {$_.Name -like "*wwa*" }

    Get tired of typing? Too hard to see a big text list? Send it to PowerShell Grid-View and you get a UI for inventory with search!
    Get-AppxPackage  Out-GridView

    With variables, I can even just get a quick count:
    $packages = Get-AppxPackage
    $packages.Count

    How do I remove a package?

    Removing an AppX package needs the package moniker. You can use variables again and inventory to help:
    $toRemove = Get-AppxPackage | Where-Object {$_.Name -like "*wwa*" }
    Remove-AppxPackage $toRemove.PackageMoniker

    So Cool, What else can I do with PowerShell?

    How about sorting and getting a customized table of inventory with just Package Name and Install location:
    Get-AppxPackage  | Sort-Object Name | Format-Table Name,InstallLocation -Auto

    WOW, with PowerShell you can even take inventory and generate an HTML file:
    Get-AppxPackage | ConvertTo-Html | Set-Content temp.html

    Since PowerShell knows how to navigate XML natively, you can even navigate the Package Manifest with PowerShell. Here is getting the App ID from an app you searched for!
    $xml = Get-AppxPackage | Where-Object {$_.Name -like "*wwa*" } | Get-AppxPackageManifest
    $xml.Package.Applications.Application.Id

    How about navigating the event log to debug problems?

    One of the most common things that everyone is looking for is event logs when things go wrong. With PowerShell, not only do you get better error messages directly from the AppX deployment engine, you can easily query for the last 10 ETW messages from the deployment engine!
    Get-WinEvent -logname Microsoft-Windows-appx* | Select-Object -last 10 | Format-List -Property Message

     

    Thursday, September 15, 2011 12:11 AM
    Moderator
  • Very nice! Cribbed a copy to my blog with some formatting refinements

    Folks who are interested in more details should check out John Sheehan's session for more details:

    PLAT-905C Under the hood: installation and updates for Metro style apps

    Tomorrow (Day 3 - Sep'15) at 10:30am


    The architect must be a prophet...a prophet in the true sense of the term...if he can't see at least ten years ahead don't call him an architect - Frank Lloyd Wright

    Looking for the Spike...
    http://blogs.msdn.com/b/howardk/

    Thursday, September 15, 2011 4:21 AM
  • Hi Carlos, have you ever encountered such problem: when install a app through powershell, the app could not be found on desktop and "app search" but it could be found with powershell commands: "Get-AppxPackage". 

    BTW: the app is written by myself.


    dollar zhang

    Tuesday, June 12, 2012 7:59 AM
  • Check out this cmdlet for launching apps: https://win8powershell.codeplex.com/ It uses publicly defined APIs
    Monday, July 15, 2013 5:44 PM