Skip to content

Commit

Permalink
Merge pull request #18 from AmbitionsTechnologyGroup/RCShoemaker-Inst…
Browse files Browse the repository at this point in the history
…all-Winget-1

Created function for Install-Winget
  • Loading branch information
RCShoemaker authored May 28, 2021
2 parents 7fc106f + 2615ddd commit c20b15f
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions ATG-PS-Functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,99 @@ Function Install-O365ProofPointConnectors {
}
}

Function Install-WinGet {
<#
.DESCRIPTION
Installs winget, Microsoft's answer to apt-get and choco.
.LINK
https://github.com/microsoft/winget-cli
.LINK
https://docs.microsoft.com/en-us/windows/package-manager/winget/
#>
$WGLatestWeb = iwr https://github.com/microsoft/winget-cli/releases/latest -UseBasicParsing
$WGLatestLink = "https://github.com" + ($WGLatestWeb.Links | Where-Object {$_.href -like "*appxbundle*"}).href

$GetWinGet = {
$WGLatestWeb = iwr https://github.com/microsoft/winget-cli/releases/latest -UseBasicParsing
$WGLatestLink = "https://github.com" + ($WGLatestWeb.Links | Where-Object {$_.href -like "*appxbundle*"}).href
Write-Host "Installing the latest version of winget from:`n $WGLatestLink"
$DownloadURL = $WGLatestLink
$DownloadLocation = "$env:TEMP\"
$LocalFilePath = Join-Path -Path $DownloadLocation -ChildPath "Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.appxbundle"
If (Test-Path $LocalFilePath) {Remove-Item -Path $LocalFilePath -Force -ErrorAction SilentlyContinue}
Write-Host "Downloading Desktop App Installer"
$progressPreference = 'silentlyContinue'
Invoke-WebRequest -Uri $DownloadURL -OutFile $LocalFilePath

Add-AppxPackage -Path $LocalFilePath
Remove-Item -Path $LocalFilePath -Force -ErrorAction SilentlyContinue
}

$GetWinGetDependancies = {
Write-Host "Checking Dependancies"
## C++ Runtime framework packages for Desktop Bridge - https://docs.microsoft.com/en-us/troubleshoot/cpp/c-runtime-packages-desktop-bridge#how-to-install-and-update-desktop-framework-packages
## x86 version
$Installed_X86_VCLibs = Get-AppxPackage | Where-Object {$_.Name -Match "Microsoft.VCLibs.140.00.UWPDesktop" -and $_.Architecture -Match "X86"}
If (-not ($Installed_X86_VCLibs)) {
$DownloadURL = 'https://aka.ms/Microsoft.VCLibs.x86.14.00.Desktop.appx'
$DownloadLocation = "$env:TEMP\"
$LocalFilePath = Join-Path -Path $DownloadLocation -ChildPath "Microsoft.VCLibs.x86.14.00.Desktop.appx"
If (Test-Path $LocalFilePath) {Remove-Item -Path $LocalFilePath -Force -ErrorAction SilentlyContinue}
Write-Host "Downloading $DownloadURL"
$progressPreference = 'silentlyContinue'
Invoke-WebRequest -Uri $DownloadURL -OutFile $LocalFilePath
If ($PSVersionTable.PSEdition -eq "Core") {Import-module "Appx" -UseWindowsPowerShell}
Write-Host "Installing $LocalFilePath"
Add-AppxPackage -Path $LocalFilePath
Remove-Item -Path $LocalFilePath -Force -ErrorAction SilentlyContinue
}
## x64 version
If ([Environment]::Is64BitOperatingSystem){
$Installed_X64_VCLibs = Get-AppxPackage | Where-Object {$_.Name -Match "Microsoft.VCLibs.140.00.UWPDesktop" -and $_.Architecture -Match "X64"}
If (-not ($Installed_X64_VCLibs)) {
$DownloadURL = 'https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx'
$DownloadLocation = "$env:TEMP\"
$LocalFilePath = Join-Path -Path $DownloadLocation -ChildPath "Microsoft.VCLibs.x64.14.00.Desktop.appx"
If (Test-Path $LocalFilePath) {Remove-Item -Path $LocalFilePath -Force -ErrorAction SilentlyContinue}
Write-Host "Downloading $DownloadURL"
$progressPreference = 'silentlyContinue'
Invoke-WebRequest -Uri $DownloadURL -OutFile $LocalFilePath
If ($PSVersionTable.PSEdition -eq "Core") {Import-module "Appx" -UseWindowsPowerShell}
Write-Host "Installing $LocalFilePath"
Add-AppxPackage -Path $LocalFilePath
Remove-Item -Path $LocalFilePath -Force -ErrorAction SilentlyContinue
}
}
}

If (Get-Command winget -ErrorAction SilentlyContinue) {
Write-Host "WinGet is already installed."
$WGVersion = winget -v
If ($WGLatestLink -match $WGVersion) {
Write-Host "The installed version $WGVersion is up to date."
} Else {
Write-Host "The installed version $WGVersion is out of date."
If ($PSVersionTable.PSEdition -eq "Core") {Powershell.exe -NonInteractive -Command $GetWinGet} Else {$GetWinGet | IEX}
$WGVersion2 = winget -v
If ($WGVersion -ne $WGVersion2) {
Write-Host "Winget $WGVersion2 installed successfully"
} Else {
Write-Error "Winget did not install successfully"
}
}
} Else {
Write-Host "WinGet is not installed."
If ($PSVersionTable.PSEdition -eq "Core") {Powershell.exe -NonInteractive -Command $GetWinGetDependancies} Else {$GetWinGetDependancies | IEX}
If ($PSVersionTable.PSEdition -eq "Core") {Powershell.exe -NonInteractive -Command $GetWinGet} Else {$GetWinGet | IEX}
If (Get-Command winget -ErrorAction SilentlyContinue) {
$WGVersion = winget -v
Write-Host "Winget $WGVersion installed successfully"
} Else {
Write-Error "Winget did not install successfully"
}
}
}

Function Invoke-Win10Decrap {
Write-Host "Windows 10 Decrapifier"
$progressPreference = 'silentlyContinue'
Expand Down

0 comments on commit c20b15f

Please sign in to comment.