added Download-File function to Tools.ps1
added Install-VLC.ps1 script
This commit is contained in:
@@ -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 } }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user