Issue
So I am using Chocolatey to help with Package installs on a computer and am wondering if there is a way to for loop through this in powershell. I am more familiar with for loops in Bash with Linux and Mac then I am with Windows, so was wondering if someone can give me some insights,
I basically am running the following scenario:
choc install <package_name> -y
And I need to install all of these packages at once:
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
How can I accomplish this?
Solution
When you run an external command (or any command), the output of that command can be piped into a PowerShell command. Since your command outputs single lines containing a package name, that output can be piped into Foreach-Object where each package (object in PowerShell terms) can be processed.
<package output command> | Foreach-Object { choc install $_ -y }
The current object being processed by Foreach-Object
is $_
or $PSItem
.
Answered By - AdminOfThings Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.