简体   繁体   English

组合多个Powershell命令

[英]Combining multiple powershell commands

I am trying to remove some of the superfluous applications that come with Windows 10 and currently using the below command, for example, if I want to remover 3D Builder, I use: 我试图删除Windows 10附带的一些多余应用程序,并且当前正在使用以下命令,例如,如果要删除3D Builder,请使用:

Get-AppxPackage *3dbuilder* | Remove-AppxPackage

Similarly, if I need to remove other applications, I need to keep reusing the above command replacing the app name. 同样,如果需要删除其他应用程序,则需要继续重复使用以上命令替换应用程序名称。 Is there a way to remove multiple applications with a single command? 有没有办法用一个命令删除多个应用程序? I do not want to write a powershell script as I need to set the execution policy. 我不想编写Powershell脚本,因为我需要设置执行策略。

The other option is to use this as shown below, but, I would want to see what I remove. 另一个选择是使用此功能 ,如下所示,但是,我想查看删除的内容。

Get-AppxPackage -AllUsers | Remove-AppxPackage

Given what you have described, I'd use a regex match against the package name: 根据您的描述,我将对包名称使用正则表达式匹配项:

First, run this to verify what you are about to remove: 首先,运行此命令以验证您将要删除的内容:

Get-AppXPackage | Where-Object { $_.Name -imatch "(3dbuilder|package2|package3)$" }  | Remove-AppxPackage -WhatIf

Then, remove the -WhatIf to actually have Remove-AppXPackage run. 然后,删除-WhatIf以实际运行Remove-AppXPackage。

The regex I show above does essentially an ends-with match. 我在上面显示的正则表达式实质上完成了匹配。 It looks for the packages with names that end with "3dbuilder", "package2", or "package3". 它寻找名称以“ 3dbuilder”,“ package2”或“ package3”结尾的软件包。 You can add or remove package names from the list, using the Pipe symbol to separate them. 您可以从列表中添加或删除包名称,使用管道符号将它们分开。 This is because it appears there are some random-ish characters in front of the package names that you probably don't want to type in. 这是因为在软件包名称前面似乎有一些不希望出现的字符,您可能不想输入。

Regexes can match greedily, so be sure to run with -WhatIf first to verify you are only removing what you want! 正则表达式可以贪婪地匹配,因此请确保首先使用-WhatIf来运行,以确认您仅删除了想要的东西!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM