From 77cf4d6276ab1a74269e7f062f17a456220f5ddd Mon Sep 17 00:00:00 2001 From: dyoder Date: Mon, 19 Oct 2020 11:24:07 -0400 Subject: [PATCH] added Download-File function to Tools.ps1 added Install-VLC.ps1 script --- Install-VLC.ps1 | 27 +++++++++++++++++++++++++++ Tools.ps1 | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 Install-VLC.ps1 diff --git a/Install-VLC.ps1 b/Install-VLC.ps1 new file mode 100644 index 0000000..3ce0d2e --- /dev/null +++ b/Install-VLC.ps1 @@ -0,0 +1,27 @@ +. $([Scriptblock]::Create((New-Object Net.WebClient).DownloadString('https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Tools.ps1'))) + +## Make sure we're running as admin +If ( IsAdmin ) +{ + ## Get the correct URL + If ( Is64bit) + { $URL = 'https://get.videolan.org/vlc/3.0.11/win64/vlc-3.0.11-win64.exe' } + Else + { $URL = 'https://ftp.osuosl.org/pub/videolan/vlc/3.0.11/win32/vlc-3.0.11-win32.exe' } + + ## Download file and get local file name + $Installer = Download-File $URL + + If ( Test-Path $Installer ) + { + ## Run silent install + Try { Start-Process $Installer -ArgumentList "/S" -Wait } + Catch { Write-Output $_.Exception.Message } + + ## Delete the file we downloaded + Try { Remove-Item $Installer -Force } + Catch { Write-Output $_.Exception.Message } + } + Else { Write-Output "The URL was not downloaded correctly: ${URL}" } +} +Else { Write-Output "You must run this script as an administrator" } \ No newline at end of file diff --git a/Tools.ps1 b/Tools.ps1 index a9d0cdd..063736c 100644 --- a/Tools.ps1 +++ b/Tools.ps1 @@ -155,14 +155,44 @@ Return [version]$Return.Trim('.') Function IsURLValid { param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$URL) -$HTTPRequest = [System.Net.WebRequest]::Create($URL) -$HTTPResponse = $HTTPRequest.GetResponse() -$HTTPStatus = [int]$HTTPResponse.StatusCode -$HTTPResponse.Close() +Try +{ + $HTTPRequest = [System.Net.WebRequest]::Create($URL) + $HTTPResponse = $HTTPRequest.GetResponse() + $HTTPStatus = [int]$HTTPResponse.StatusCode + $HTTPResponse.Close() +} +Catch {} If ($HTTPStatus -eq 200) { Return $true } Else { Return $false } } +Function Download-File +{ +param( + [Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$URL, + [Parameter(Mandatory=$false,ValueFromPipeline=$false)][string]$File +) +$LogName = $MyInvocation.MyCommand +If ( !($File) ) { $File = '{0}\{1}' -f $Env:TEMP, (Split-Path $URL -Leaf) } +If ( IsURLValid $URL ) +{ + If ( Test-Path $File ) + { + Log "Deleting existing file: ""${File}""" -Name $LogName + Try { Remove-Item $File -Force } + Catch { $_.Exception.Message | Log -Name $LogName } + } + Log "Downloading ""${URL}"" to ""${File}""" -Name $LogName + Try { (New-Object System.Net.WebClient).DownloadFile($URL,$File) } + Catch { $_.Exception.Message | Log -Name $LogName } + If ( Test-Path $File ) + { Return $File } + Else { Log "The file was downloaded but was immediately deleted" -Name $LogFile ; Return $false } +} +Else { Log "URL is not valid or file cannot be reached: ${URL}" -Name $LogName } +} + ## Function to compare current Windows version with a supplied version ## The value supplied must be a string and must include at least 1 decimal Function IsWindowsVersion @@ -217,3 +247,4 @@ switch ( $(Get-CimInstance -ClassName Win32_OperatingSystem -Property OSArchitec ## Function to determine if the Powershell process is 64-bit or not Function Is64bitShell { If ( [System.Environment]::Is64BitProcess ) { Return $true } Else { Return $false } } +