|
| 1 | +<#PSScriptInfo |
| 2 | +
|
| 3 | +.Version |
| 4 | + 1.0 |
| 5 | +.Guid |
| 6 | + a56f96f1-27d1-4d1d-85aa-ca206cee7fe5 |
| 7 | +.Author |
| 8 | + Thomas Malkewitz @dotps1 |
| 9 | +.Tags |
| 10 | + Google, Chrome, Msi |
| 11 | +.ProjectUri |
| 12 | + https://github.com/dotps1/PSFunctions |
| 13 | +.ReleaseNotes |
| 14 | + Initial Release. |
| 15 | +
|
| 16 | +#> |
| 17 | + |
| 18 | +<# |
| 19 | +
|
| 20 | +.SYNOPSIS |
| 21 | + Gets the Google Chrome for Enterprise msi. |
| 22 | +.DESCRIPTION |
| 23 | + Gets the Latest version of the Google Chrome for Enterprise msi. |
| 24 | +.INPUTS |
| 25 | + System.String |
| 26 | +.OUTPUTS |
| 27 | + System.IO.FileInfo |
| 28 | +.PARAMETER Path |
| 29 | + System.String |
| 30 | + The path to save the msi installer. |
| 31 | +.PARAMETER Architecture |
| 32 | + System.String |
| 33 | + The specified OS Architecture of the installer to get. Defaults to "All" (x64 and x86). |
| 34 | +.EXAMPLE |
| 35 | + PS C:\> Get-GoogleChromeMsiInstaller |
| 36 | + |
| 37 | +
|
| 38 | + Directory: C:\Users\dotps1\Downloads |
| 39 | +
|
| 40 | +
|
| 41 | + Mode LastWriteTime Length Name |
| 42 | + ---- ------------- ------ ---- |
| 43 | + -a---- 12/12/2018 4:11 PM 55500800 googlechromestandaloneenterprise.msi |
| 44 | + -a---- 12/12/2018 4:11 PM 56463360 googlechromestandaloneenterprise64.msi |
| 45 | +.EXAMPLE |
| 46 | + PS C:\> Get-GoogleChromeMsiInstaller -Path C:\Temp -Architecture x86 |
| 47 | + |
| 48 | +
|
| 49 | + Directory: C:\Users\dotps1\Downloads |
| 50 | +
|
| 51 | +
|
| 52 | + Mode LastWriteTime Length Name |
| 53 | + ---- ------------- ------ ---- |
| 54 | + -a---- 12/12/2018 4:11 PM 55500800 googlechromestandaloneenterprise.msi |
| 55 | +.NOTES |
| 56 | + The installer download links are renedered on the google page with javascript, |
| 57 | + these links are fetched with an Internet Explorer COM object to cause that javascript to run and expose the links. |
| 58 | +.LINK |
| 59 | + https://dotps1.github.io |
| 60 | +
|
| 61 | +#> |
| 62 | + |
| 63 | + |
| 64 | +[CmdletBinding( |
| 65 | + ConfirmImpact = "High", |
| 66 | + SupportsShouldProcess = $true |
| 67 | +)] |
| 68 | +[OutputType( |
| 69 | + [System.IO.FileInfo] |
| 70 | +)] |
| 71 | + |
| 72 | +param ( |
| 73 | + [Parameter( |
| 74 | + ValueFromPipeline = $true, |
| 75 | + ValueFromPipelineByPropertyName = $true |
| 76 | + )] |
| 77 | + [String] |
| 78 | + $Path = "${env:USERPROFILE}\Downloads", |
| 79 | + |
| 80 | + [Parameter()] |
| 81 | + [ValidateSet( |
| 82 | + "All", "X86", "X64" |
| 83 | + )] |
| 84 | + [String] |
| 85 | + $Architecture = "All" |
| 86 | +) |
| 87 | + |
| 88 | +begin { |
| 89 | + if (-not (Test-Path -Path $Path)) { |
| 90 | + try { |
| 91 | + Out-Null -InputObject ( |
| 92 | + New-Item -Path $Path -ItemType Directory -ErrorAction Stop |
| 93 | + ) |
| 94 | + } catch { |
| 95 | + $PSCmdlet.ThrowTerminatingError( |
| 96 | + $_ |
| 97 | + ) |
| 98 | + |
| 99 | + break |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + $downloader = New-Object -TypeName System.Net.WebClient |
| 104 | +} |
| 105 | + |
| 106 | +process { |
| 107 | + if ($Architecture -in @("All", "X86")) { |
| 108 | + $downloadUriX86 = 'https://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi' |
| 109 | + $msiX86 = Join-path -Path $Path -ChildPath "googlechromestandaloneenterprise.msi" |
| 110 | + |
| 111 | + if (Test-Path -Path $msiX86) { |
| 112 | + $shouldProcess = $PSCmdlet.ShouldProcess( |
| 113 | + $msiX86, "Overwrite" |
| 114 | + ) |
| 115 | + } else { |
| 116 | + $shouldProcess = $true |
| 117 | + } |
| 118 | + |
| 119 | + if ($shouldProcess) { |
| 120 | + $downloader.DownloadFile( |
| 121 | + $downloadUriX86, $msiX86 |
| 122 | + ) |
| 123 | + |
| 124 | + Write-Output -InputObject ( Get-Item -Path $msiX86 ) |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + if ($Architecture -in @("All", "X64")) { |
| 129 | + $downloadUriX64 = 'https://dl.google.com/edgedl/chrome/install/GoogleChromeStandaloneEnterprise64.msi' |
| 130 | + $msiX64 = Join-path -Path $Path -ChildPath "googlechromestandaloneenterprise64.msi" |
| 131 | + |
| 132 | + if (Test-Path -Path $msiX64) { |
| 133 | + $shouldProcess = $PSCmdlet.ShouldProcess( |
| 134 | + $msiX64, "Overwrite" |
| 135 | + ) |
| 136 | + } else { |
| 137 | + $shouldProcess = $true |
| 138 | + } |
| 139 | + |
| 140 | + if ($shouldProcess) { |
| 141 | + $downloader.DownloadFile( |
| 142 | + $downloadUriX64, $msiX64 |
| 143 | + ) |
| 144 | + |
| 145 | + Write-Output -InputObject ( Get-Item -Path $msiX64 ) |
| 146 | + } |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | +end { |
| 151 | + $downloader.Dispose() |
| 152 | +} |
0 commit comments