【发布时间】:2020-03-30 13:59:50
【问题描述】:
所以我正在使用 Chocolatey 来帮助在计算机上安装包,我想知道是否有一种方法可以在 powershell 中循环遍历它。我对 Linux 和 Mac 的 Bash 中的 for 循环比 Windows 更熟悉,所以想知道是否有人可以给我一些见解,
我基本上是在运行以下场景:
choc install <package_name> -y
我需要一次安装所有这些包:
Chocolatey v0.10.15
androidstudio 3.5.3.0
atom 1.41.0.20191029
awk 4.2.132
chocolatey 0.10.15
chocolatey-core.extension 1.3.5
chocolatey-dotnetfx.extension 1.0.1
chocolatey-visualstudio.extension 1.8.1
chocolatey-windowsupdate.extension 1.0.4
CrystalReports2010Runtime 13.0.18
curl 7.67.0
docker 99.0.0
docker-cli 19.03.3
DotNet3.5 3.5.20160716
dotnetcore-runtime 3.1.0
dotnetcoresdk 1.0.1
dotnetfx 4.8.0.20190930
filezilla 3.46.0
flashplayeractivex 32.0.0.303
flashplayerplugin 32.0.0.293
gawk 5.0.1
gimp 2.10.14
git 2.24.0
git.install 2.24.0
gitlab-runner 12.5.0
GoogleChrome 80.0.3987.116
gpg4win-vanilla 2.3.4.20191021
grafana 6.3.6
grep 2.1032
jdk8 8.0.231
jenkins-x 2.0.1082
jq 1.6
KB2533623 1.0.4
KB2919355 1.0.20160915
KB2919442 1.0.20160915
KB2999226 1.0.20181019
KB3033929 1.0.5
KB3035131 1.0.3
kubernetes-cli 1.17.0
less 5.51.0.20191024
minikube 1.6.1
mysql-odbc 5.3.12
nano 2.5.3
nodejs.install 13.3.0
openssh 8.0.0.1
openvpn 2.4.7
postgresql 12.1
postgresql12 12.1
postman 7.13.0
prometheus 2.2.1
prometheus-wmi-exporter.install 0.9.0
putty 0.73
putty.portable 0.73
python 3.8.0
python3 3.8.0
random-number-generator 3.0.0
ruby 2.6.5.1
rubymine 2019.2.4
runinbash 0.1.1
sed 4.7
teamviewer 15.0.8397
unzip 6.0
vagrant 2.2.6
vault 1.3.0
vcredist140 14.23.27820
vcredist2013 12.0.40660.20180427
vcredist2015 14.0.24215.20170201
vim 8.1.2318
visioviewer 16.0
visioviewer2016 16.0
visualstudio-installer 2.0.1
visualstudio2019community 16.3.10.0
vlc 3.0.8
Wget 1.20.3.20190531
我怎样才能做到这一点?
【问题讨论】:
-
您可以将您的包输出命令通过管道传输到
Foreach-Object {}。基本上这将是<package output command> | Foreach-Object { choc install $_ -y },其中$_将是您命令的每一行输出。 -
让我试一试。
-
非常感谢一百万 @AdminOfThings
标签: windows powershell scripting package-managers chocolatey