Skip to content

Instantly share code, notes, and snippets.

@jurandysoares
Created April 15, 2024 19:33
Show Gist options
  • Save jurandysoares/855193ec5d94c2d496f3c33667c48d60 to your computer and use it in GitHub Desktop.
Save jurandysoares/855193ec5d94c2d496f3c33667c48d60 to your computer and use it in GitHub Desktop.
PowerShell: Instalação de pacotes a partir de uma multiline string
# https://community.spiceworks.com/t/powershell-convert-multi-line-string-variable-into-array/765578
$pacotesTxt = "GitHub.GitHubDesktop
Git.Git
Microsoft.VisualStudioCode
Python.Python.3.12"
$pacotesVetor = $pacotesTxt -split "`r`n"
foreach ($pacote in $pacotesVetor) {
Write-Host $pacote
winget list -q $pacote | Out-Null
$pacoteInstalado = $?
# https://github.com/microsoft/winget-cli/issues/291
if (-not $pacoteInstalado) {
winget install --id $pacote --source winget
}
else {
"O pacote com ID ${pacote} já está instalado."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment