added Download-File function to Tools.ps1
added Install-VLC.ps1 script
This commit is contained in:
@@ -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" }
|
||||||
@@ -155,14 +155,44 @@ Return [version]$Return.Trim('.')
|
|||||||
Function IsURLValid
|
Function IsURLValid
|
||||||
{
|
{
|
||||||
param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$URL)
|
param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$URL)
|
||||||
|
Try
|
||||||
|
{
|
||||||
$HTTPRequest = [System.Net.WebRequest]::Create($URL)
|
$HTTPRequest = [System.Net.WebRequest]::Create($URL)
|
||||||
$HTTPResponse = $HTTPRequest.GetResponse()
|
$HTTPResponse = $HTTPRequest.GetResponse()
|
||||||
$HTTPStatus = [int]$HTTPResponse.StatusCode
|
$HTTPStatus = [int]$HTTPResponse.StatusCode
|
||||||
$HTTPResponse.Close()
|
$HTTPResponse.Close()
|
||||||
|
}
|
||||||
|
Catch {}
|
||||||
If ($HTTPStatus -eq 200) { Return $true }
|
If ($HTTPStatus -eq 200) { Return $true }
|
||||||
Else { Return $false }
|
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
|
## Function to compare current Windows version with a supplied version
|
||||||
## The value supplied must be a string and must include at least 1 decimal
|
## The value supplied must be a string and must include at least 1 decimal
|
||||||
Function IsWindowsVersion
|
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 to determine if the Powershell process is 64-bit or not
|
||||||
Function Is64bitShell
|
Function Is64bitShell
|
||||||
{ If ( [System.Environment]::Is64BitProcess ) { Return $true } Else { Return $false } }
|
{ If ( [System.Environment]::Is64BitProcess ) { Return $true } Else { Return $false } }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user