2020-09-07 13:43:37 -04:00
|
|
|
## Function to log activity to the configured log directory
|
|
|
|
|
Function global:Log
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## Function to determine if the current user context is an Administrator
|
|
|
|
|
Function global:IsAdmin
|
|
|
|
|
{
|
|
|
|
|
If ( ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) )
|
|
|
|
|
{ Return $true } Else { Return $false }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## Runs a script from the repo
|
|
|
|
|
Function global:Run-PSScript
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[string]$Type='management-scripts',
|
|
|
|
|
[string]$Name,
|
|
|
|
|
[string]$Arguments)
|
|
|
|
|
|
|
|
|
|
## Get rid of null arguments
|
|
|
|
|
If ( $Arguments -eq "null" ) { $Arguments = $null }
|
|
|
|
|
|
|
|
|
|
## Make sure $Name and $Type are defined
|
|
|
|
|
If ( $Name -and $Type )
|
|
|
|
|
{
|
|
|
|
|
## Form the URL to the specified script
|
|
|
|
|
$URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1"
|
|
|
|
|
|
|
|
|
|
## Get the script
|
|
|
|
|
Write-Output "Retrieving : ${Name}.ps1"
|
|
|
|
|
Try { $Script = (New-Object Net.WebClient).DownloadString($URL) }
|
|
|
|
|
Catch { Write-Output $_.Exception.Message }
|
|
|
|
|
|
|
|
|
|
## Make a script block
|
|
|
|
|
Try { $ScriptBlock = [Scriptblock]::Create($Script) }
|
|
|
|
|
Catch { Write-Output $_.Exception.Message }
|
|
|
|
|
|
|
|
|
|
## Run the script any any arguments
|
|
|
|
|
Write-Output "Executing: ${Name}.ps1 ${Arguments}"
|
|
|
|
|
Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments }
|
|
|
|
|
Catch { Write-Output $_.Exception.Message }
|
|
|
|
|
}
|
|
|
|
|
Else { Write-Output "No script or type was specified" }
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 15:26:19 -04:00
|
|
|
## Function to return a Powershell version object from a string
|
2020-09-07 13:43:37 -04:00
|
|
|
Function Get-Version
|
|
|
|
|
{
|
|
|
|
|
param([string]$Version)
|
|
|
|
|
[int]$Sets = 4
|
|
|
|
|
$VersionArray = $Version.Split('.')
|
|
|
|
|
If ( $VersionArray.Count -le $Sets ) { $Sets = $VersionArray.Count }
|
|
|
|
|
For ($i = 0; $i -le ($Sets - 1); $i++)
|
|
|
|
|
{ $Return = '{0}.{1}' -f $Return, $VersionArray[$i] }
|
|
|
|
|
Return [version]$Return.Trim('.')
|
2020-09-07 20:18:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## Function to compare current Windows version with a supplied version
|
|
|
|
|
Function IsWindowsVersion
|
|
|
|
|
{
|
|
|
|
|
param(
|
2020-09-09 16:46:21 -04:00
|
|
|
[Parameter(Mandatory=$true,ParameterSetName='gt')][string]$gt,
|
|
|
|
|
[Parameter(Mandatory=$true,ParameterSetName='ge')][string]$ge,
|
|
|
|
|
[Parameter(Mandatory=$true,ParameterSetName='lt')][string]$lt,
|
|
|
|
|
[Parameter(Mandatory=$true,ParameterSetName='le')][string]$le,
|
|
|
|
|
[Parameter(Mandatory=$true,ParameterSetName='eq')][string]$eq
|
2020-09-07 20:18:06 -04:00
|
|
|
)
|
|
|
|
|
[version]$WindowsVersion = [System.Environment]::OSVersion.Version
|
|
|
|
|
switch ($PSCmdlet.ParameterSetName)
|
|
|
|
|
{
|
|
|
|
|
'gt' { If ( $WindowsVersion -gt (Get-Version $gt) ) { Return $true } Else { Return $false } }
|
|
|
|
|
'ge' { If ( $WindowsVersion -ge (Get-Version $ge) ) { Return $true } Else { Return $false } }
|
|
|
|
|
'lt' { If ( $WindowsVersion -lt (Get-Version $lt) ) { Return $true } Else { Return $false } }
|
|
|
|
|
'le' { If ( $WindowsVersion -le (Get-Version $le) ) { Return $true } Else { Return $false } }
|
|
|
|
|
'eq' { If ( $WindowsVersion -eq (Get-Version $eq) ) { Return $true } Else { Return $false } }
|
|
|
|
|
}
|
2020-09-09 16:46:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
## Function to compare current Windows version with a supplied version
|
|
|
|
|
Function IsWindowsBuild
|
|
|
|
|
{
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory=$true,ParameterSetName='gt')][string]$gt,
|
|
|
|
|
[Parameter(Mandatory=$true,ParameterSetName='ge')][string]$ge,
|
|
|
|
|
[Parameter(Mandatory=$true,ParameterSetName='lt')][string]$lt,
|
|
|
|
|
[Parameter(Mandatory=$true,ParameterSetName='le')][string]$le,
|
|
|
|
|
[Parameter(Mandatory=$true,ParameterSetName='eq')][string]$eq
|
|
|
|
|
)
|
|
|
|
|
[int]$WindowsBuild = [System.Environment]::OSVersion.Version.Build
|
|
|
|
|
switch ($PSCmdlet.ParameterSetName)
|
|
|
|
|
{
|
|
|
|
|
'gt' { If ( $WindowsBuild -gt $gt ) { Return $true } Else { Return $false } }
|
|
|
|
|
'ge' { If ( $WindowsBuild -ge $ge ) { Return $true } Else { Return $false } }
|
|
|
|
|
'lt' { If ( $WindowsBuild -lt $lt ) { Return $true } Else { Return $false } }
|
|
|
|
|
'le' { If ( $WindowsBuild -le $le ) { Return $true } Else { Return $false } }
|
|
|
|
|
'eq' { If ( $WindowsBuild -eq $eq ) { Return $true } Else { Return $false } }
|
|
|
|
|
}
|
2020-09-07 13:43:37 -04:00
|
|
|
}
|