Skip to content

Instantly share code, notes, and snippets.

@scottleedavis
Last active October 1, 2023 18:59
Show Gist options
  • Save scottleedavis/2eec47dd90206018b9d0b678de6d8521 to your computer and use it in GitHub Desktop.
Save scottleedavis/2eec47dd90206018b9d0b678de6d8521 to your computer and use it in GitHub Desktop.
admin powershell 'add all install applications to chocolately'
# Assuming $output contains the result of 'choco list -i'
$output = choco list -i
# Split the output into lines
$lines = $output -split "`n"
# Find the index of the phrase "packages installed."
$startIndex = [Array]::IndexOf($lines, ($lines | Where-Object { $_ -match "packages installed\.$" }))
# Find the index of the phrase "applications not managed with Chocolatey."
$endIndex = [Array]::IndexOf($lines, ($lines | Where-Object { $_ -match "applications not managed with Chocolatey\.$" }))
# Extract the applications between the two indices
$unmanagedApps = $lines[($startIndex+1)..($endIndex-1)]
$unmanagedApps
# Filter out the application names (before the | character)
$appNames = $unmanagedApps | ForEach-Object { ($_ -split "\|")[0].Trim() }
foreach ($app in $appNames) {
# Check if the application is not installed via Chocolatey
$chocoList = choco list --localonly
if ($chocoList -notcontains $app) {
# Try installing the application
choco install $app -y
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment