Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.24 KB | None | 0 0
  1. # Save this file as a .PS1 file and run with powershell
  2. ##########################################################################################################
  3.  
  4.  
  5.  
  6. <#
  7. The sample scripts are not supported under any Microsoft standard support
  8. program or service. The sample scripts are provided AS IS without warranty
  9. of any kind. Microsoft further disclaims all implied warranties including,
  10. without limitation, any implied warranties of merchantability or of fitness for
  11. a particular purpose. The entire risk arising out of the use or performance of
  12. the sample scripts and documentation remains with you. In no event shall
  13. Microsoft, its authors, or anyone else involved in the creation, production, or
  14. delivery of the scripts be liable for any damages whatsoever (including,
  15. without limitation, damages for loss of business profits, business interruption,
  16. loss of business information, or other pecuniary loss) arising out of the use
  17. of or inability to use the sample scripts or documentation, even if Microsoft
  18. has been advised of the possibility of such damages.
  19. #>
  20.  
  21. #requires -Version 3
  22.  
  23. <#
  24. .SYNOPSIS
  25. The RemoveAppxPackage command will remove Windows Store Appx packages.
  26.  
  27. .DESCRIPTION
  28. This script can help you to remove several Windows Store Apps at one time.
  29.  
  30. .EXAMPLE
  31. PS C:\> C:\Script\RemoveWindowsStoreApp.ps1
  32.  
  33. ID App name
  34. 1 Microsoft.Media.PlayReadyClient.2
  35. 2 Microsoft.Media.PlayReadyClient.2
  36. 3 CheckPoint.VPN
  37. 4 f5.vpn.client
  38. 5 FileManager
  39. 6 JuniperNetworks.JunosPulseVpn
  40. 7 Microsoft.MoCamera
  41. 8 SonicWALL.MobileConnect
  42. 9 windows.immersivecontrolpanel
  43. 10 winstore
  44. 11 Microsoft.BingSports
  45. 12 Microsoft.BingTravel
  46. 13 Microsoft.SkypeApp
  47. 14 Microsoft.BingFinance
  48. 15 Microsoft.HelpAndTips
  49. 16 Microsoft.BingFoodAndDrink
  50. 17 Microsoft.BingHealthAndFitness
  51. 18 Microsoft.BingNews
  52. 19 microsoft.windowscommunicationsapps
  53. 20 Microsoft.WindowsSoundRecorder
  54. 21 Microsoft.WindowsScan
  55. 22 Microsoft.ZuneMusic
  56. 23 Microsoft.VCLibs.120.00
  57. 24 Microsoft.WindowsAlarms
  58. 25 Microsoft.WinJS.2.0
  59. 26 Microsoft.WindowsCalculator
  60. 27 Microsoft.BingWeather
  61. 28 Microsoft.Reader
  62. 29 Microsoft.ZuneVideo
  63. 30 Microsoft.WindowsReadingList
  64. 31 Microsoft.BingMaps
  65. 32 Microsoft.XboxLIVEGames
  66. 33 Microsoft.VCLibs.120.00
  67. Which Apps do you want to remove?
  68. Input their IDs and seperate IDs by comma: 28
  69.  
  70. This example shows how to list all Windows Store apps, and remove the apps specified by user.
  71.  
  72. .LINK
  73. Windows PowerShell Advanced Function
  74. http://technet.microsoft.com/en-us/library/dd315326.aspx
  75.  
  76. .LINK
  77. Get-AppxPackage
  78. http://technet.microsoft.com/en-us/library/hh856044.aspx
  79.  
  80. .LINK
  81. Remove-AppxPackage
  82. http://technet.microsoft.com/en-us/library/hh856038.aspx
  83. #>
  84. Import-LocalizedData -BindingVariable Messages
  85.  
  86. Function PSCustomErrorRecord
  87. {
  88. #This function is used to create a PowerShell ErrorRecord
  89. Param
  90. (
  91. [Parameter(Mandatory=$true,Position=1)][String]$ExceptionString,
  92. [Parameter(Mandatory=$true,Position=2)][String]$ErrorID,
  93. [Parameter(Mandatory=$true,Position=3)][System.Management.Automation.ErrorCategory]$ErrorCategory,
  94. [Parameter(Mandatory=$true,Position=4)][PSObject]$TargetObject
  95. )
  96. Process
  97. {
  98. $exception = New-Object System.Management.Automation.RuntimeException($ExceptionString)
  99. $customError = New-Object System.Management.Automation.ErrorRecord($exception,$ErrorID,$ErrorCategory,$TargetObject)
  100. return $customError
  101. }
  102. }
  103.  
  104. Function RemoveAppxPackage
  105. {
  106. $index=1
  107. $apps=Get-AppxPackage
  108. #return entire listing of applications
  109. Write-Host "ID`t App name"
  110. foreach ($app in $apps)
  111. {
  112. Write-Host " $index`t $($app.name)"
  113. $index++
  114. }
  115.  
  116. Do
  117. {
  118. $IDs=Read-Host -Prompt "Which Apps do you want to remove? `nInput their IDs and seperate IDs by comma"
  119. }
  120. While($IDs -eq "")
  121.  
  122. #check whether input values are correct
  123. try
  124. {
  125. [int[]]$IDs=$IDs -split ","
  126. }
  127. catch
  128. {
  129. $errorMsg = $Messages.IncorrectInput
  130. $errorMsg = $errorMsg -replace "Placeholder01",$IDs
  131. $customError = PSCustomErrorRecord `
  132. -ExceptionString $errorMsg `
  133. -ErrorCategory NotSpecified -ErrorID 1 -TargetObject $pscmdlet
  134. $pscmdlet.WriteError($customError)
  135. return
  136. }
  137.  
  138. foreach ($ID in $IDs)
  139. {
  140. #check id is in the range
  141. if ($ID -ge 1 -and $ID -le $apps.count)
  142. {
  143. $ID--
  144. #Remove each app
  145. $AppName=$apps[$ID].name
  146.  
  147. Remove-AppxPackage -Package $apps[$ID] -ErrorAction SilentlyContinue
  148. if (-not(Get-AppxPackage -Name $AppName))
  149. {
  150. Write-host "$AppName has been removed successfully"
  151. }
  152. else
  153. {
  154. Write-Warning "Remove '$AppName' failed! This app is part of Windows and cannot be uninstalled on a per-user basis."
  155. }
  156. }
  157. else
  158. {
  159. $errorMsg = $Messages.WrongID
  160. $errorMsg = $errorMsg -replace "Placeholder01",$ID
  161. $customError = PSCustomErrorRecord `
  162. -ExceptionString $errorMsg `
  163. -ErrorCategory NotSpecified -ErrorID 1 -TargetObject $pscmdlet
  164. $pscmdlet.WriteError($customError)
  165. }
  166. }
  167. }
  168.  
  169. RemoveAppxPackage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement