Skip to content

Instantly share code, notes, and snippets.

@Dragod
Last active October 29, 2021 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dragod/0539737264efa59285ae957ca89eee73 to your computer and use it in GitHub Desktop.
Save Dragod/0539737264efa59285ae957ca89eee73 to your computer and use it in GitHub Desktop.
DevMachineSetup
#Install WinGet
#Based on this gist: https://gist.github.com/crutkas/6c2096eae387e544bd05cde246f23901
$hasPackageManager = Get-AppPackage -name 'Microsoft.DesktopAppInstaller'
if (!$hasPackageManager -or [version]$hasPackageManager.Version -lt [version]"1.10.0.0") {
"Installing winget Dependencies"
Write-host "`r"
Add-AppxPackage -Path 'https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx'
$releases_url = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest'
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$releases = Invoke-RestMethod -uri $releases_url
$latestRelease = $releases.assets | Where { $_.browser_download_url.EndsWith('msixbundle') } | Select -First 1
"Installing winget from $($latestRelease.browser_download_url)"
Write-host "`r"
Add-AppxPackage -Path $latestRelease.browser_download_url
}
else {
"Winget already installed"
Write-host "`r"
}
#Configure WinGet
Write-Output "Configuring winget"
Write-host "`r"
#winget config path from: https://github.com/microsoft/winget-cli/blob/master/doc/Settings.md#file-location
$settingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json";
$settingsJson =
@"
{
// For documentation on these settings, see: https://aka.ms/winget-settings
"experimentalFeatures": {
"experimentalMSStore": true,
}
}
"@;
$settingsJson | Out-File $settingsPath -Encoding utf8
#Install New apps
# $i = 'winget install --silent -e'
# $source = '-s winget'
# $agr = '--accept-package-agreements'
# $src = '--accept-source-agreements'
# Array of apps to install
# $apps = 'Microsoft.WindowsTerminal','Microsoft.VisualStudioCode','Git.Git'
# Write-Output "Installing Apps"
# foreach ($app in $apps)
# {
# Write-host "Installing:" $app
# #winget install --id $app -e -s winget --accept-source-agreements --accept-package-agreements -h
# #winget install -h -e Git.Git -s winget --accept-source-agreements --accept-package-agreements
# winget install -h -e $app -s winget --accept-source-agreements --accept-package-agreements
# }
# @{name = "Microsoft.WindowsTerminal"; source = "winget" },
$apps = @(
@{ name = "Microsoft.WindowsTerminal"},
@{ name = "Microsoft.PowerShell" },
@{ name = "Microsoft.VisualStudioCode" },
@{ name = "Git.Git" },
@{ name = "OpenJS.NodeJS.LTS" },
@{ name = "Microsoft.VisualStudio.2019.BuildTools" },
@{ name = "OpenVPNTechnologies.OpenVPN" },
@{ name = "NuGetPackageExplorer.NuGetPackageExplorer" },
@{ name = "Mozilla.Firefox" },
@{ name = "Microsoft.Teams" },
);
foreach ($app in $apps)
{
#$listApp = winget list -e -q $app.name
#if (![String]::Join("", $listApp).Contains($app.name))
# {
Write-host "Installing:" $app.name
if ($app.source -ne $null)
{
winget install -h -e $app.name -s $app.source --accept-source-agreements --accept-package-agreements
Write-host "`r"
}
else
{
winget install -h -e $app.name --accept-source-agreements --accept-package-agreements
Write-host "`r"
}
#}
# else
# {
# Write-host "Skipping Install of " $app.name
# }
}
#--- Initialize env var and run gems & node packages ---
# Create pesistent env variable for Openvpn and git, require Powershell restart to work
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\OpenVPN\bin;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;", "Machine")
# Create session env variable to install on the fly needed node global packages.
$env:Path += ";C:\Program Files\nodejs\"
#--- Refresh Environment Variables ---
RefreshEnv.cmd
Write-Output "`r"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment