Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created function for Install-Winget #18

Merged
merged 3 commits into from
May 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions ATG-PS-Functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,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