I see two potential problems with your script:
- The calls to
-AppxProvisionedPackage
most likely require elevation. When you run your script as a user it probably throws an exception. - The call to
Get-AppxPackage -allusers
requires administrator permissions. The documentation for-allusers
reads "to use this parameter, you must run the command by using administrator permissions."
It's not clear to me exactly what your goal is. Here is how I deal with the mess of tiles in the Windows 8.1 start screen:
- Create an SCCM Application with the following characteristics:
- no installer
- uninstaller that calls
Remove-AppxPackage
for a list of common apps - detection script for that list of apps
- Deploy the Application with the Uninstall Action to the affected users.
I use this strategy because it sets things up to be more surgical with which of those apps is available to specific users in the future if that turns out to be necessary.
When a user to which this Application is deployed for removal is logged in, CcmExec
eventually detects the application and invokes the uninstall command. After the uninstall command is invoked the applications should no longer be visible or available to the user.
Uninstall-Application.ps1
Here is the body of the uninstall script I use. You need to be careful about how you set up PowerShell scripts that are invoked for (un)installation because exit codes are a bit tricky to get from the script reliably.
$appList = 'Microsoft.BingSports', # ...longlist of other apps... 'Microsoft.WindowsReadingList' Get-AppxPackage | ? { $_.Name -in $appList } | % { Remove-AppxPackage $_.PackageFullName }
Detect-Application.ps1
Below is the body of the detection script I use. Note that there are some pitfalls to using PowerShell detection scripts:
- You'll need to sign the scripts if you have an
xSigned
execution policy on a client despite what Client Settings and the logs say about using-ByPass
. - The semantics of the detection script output are arcane and only unofficially documented, but IME are reliable.
- You need to cook your PowerShell detection scripts using Adam Meltzer's workaround to get them to work.
- You should also at least be aware of some quirkiness with respect to the context that PowerShell detection scripts run in.
If you do all that PowerShell detection scripts work beautifully for complicated, surgical, or unconventional detection like this.
$appList = 'Microsoft.BingSports', # ...longlist of other apps... 'Microsoft.WindowsReadingList' Get-AppxPackage | ? { $_.Name -in $appList }