functional improvements
This commit is contained in:
@@ -13,19 +13,24 @@ $LogFilePrefix = Get-Date -Format "yyyyMMddHHmmss"
|
||||
|
||||
## Make sure all the management directories exist
|
||||
If ( !(Test-Path $MSPRoot) )
|
||||
{ New-Item -Path $MSPRoot -ItemType Directory -Force | Out-Null }
|
||||
{ New-Item -Path $MSPRoot -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null }
|
||||
If ( !(Test-Path $MSPScripts) )
|
||||
{ New-Item -Path $MSPScripts -ItemType Directory -Force | Out-Null }
|
||||
{ New-Item -Path $MSPScripts -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null }
|
||||
If ( !(Test-Path $MSPTools) )
|
||||
{ New-Item -Path $MSPTools -ItemType Directory -Force | Out-Null }
|
||||
{ New-Item -Path $MSPTools -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null }
|
||||
If ( !(Test-Path $MSPLogs) )
|
||||
{ New-Item -Path $MSPLogs -ItemType Directory -Force | Out-Null }
|
||||
{ New-Item -Path $MSPLogs -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null }
|
||||
|
||||
## Function to log activity to the configured log directory
|
||||
Function Log
|
||||
{
|
||||
param([string]$Message,[string]$LogName)
|
||||
$LogEntry = "{0} - {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][string]$Message,
|
||||
[Parameter(Mandatory=$false)][switch]$Error,
|
||||
[Parameter(Mandatory=$false)][string]$LogName
|
||||
)
|
||||
If ( $Error ) { $LogEntry = "{0} - Error: {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message }
|
||||
Else { $LogEntry = "{0} - {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message }
|
||||
If ($LogName )
|
||||
{
|
||||
$LogFile = "${MSPLogs}\${LogFilePrefix}-${LogName}.log"
|
||||
@@ -50,15 +55,49 @@ If ( $Arguments -eq "null" ) { $Arguments = $null }
|
||||
If ( $Name -and $Type )
|
||||
{
|
||||
$URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1"
|
||||
Write-Output "Retrieving : ${Name}.ps1"
|
||||
Log "Retrieving : ${Name}.ps1"
|
||||
Try { $Script = (New-Object Net.WebClient).DownloadString($URL) }
|
||||
Catch { Write-Output $_.Exception.Message }
|
||||
Catch { Log -Message $_.Exception.Message -Error }
|
||||
Try { $ScriptBlock = [Scriptblock]::Create($Script) }
|
||||
Catch { Write-Output $_.Exception.Message }
|
||||
Write-Output "Executing: ${Name}.ps1 ${Arguments}"
|
||||
Catch { Log -Message $_.Exception.Message -Error }
|
||||
Log "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" }
|
||||
Catch { Log -Message $_.Exception.Message -Error }
|
||||
} Else { Log "No script or type was specified" }
|
||||
}
|
||||
|
||||
## Runs a script local to the endpoint
|
||||
Function Run-LocalInstallScript
|
||||
{
|
||||
param(
|
||||
[Parameter(Mandatory=$true)][string]$Script,
|
||||
[Parameter(Mandatory=$true)][string]$Arguments,
|
||||
[Parameter(Mandatory=$true)][string]$AppName
|
||||
)
|
||||
If ( $AppName -eq "null" ) { $AppName = $false }
|
||||
If ( $Arguments -eq "null" ) { $Arguments = $null }
|
||||
If ( Test-Path "${Script}" )
|
||||
{
|
||||
If ( $AppName )
|
||||
{
|
||||
Log "Checking for running instances of ${AppName}"
|
||||
$RunningInstances = Get-Process | Where { $_.Name -like "${AppName}" }
|
||||
If (! ($RunningInstances) )
|
||||
{
|
||||
Log "Executing: ${Script} ${Arguments}"
|
||||
Try { Start-Process "${Script}" -ArgumentList "{$Arguments}" -Wait }
|
||||
Catch { Log -Message $_.Exception.Message -Error }
|
||||
}
|
||||
Else { Log "${AppName} is currently in use and will not be installed now" }
|
||||
}
|
||||
Else
|
||||
{
|
||||
Log "Executing: ${Script} ${Arguments}"
|
||||
Try { Start-Process "${Script}" -ArgumentList "{$Arguments}" -Wait }
|
||||
Catch { Log -Message $_.Exception.Message -Error }
|
||||
}
|
||||
}
|
||||
Else { Log "The specified script does not exist: ${Script}" }
|
||||
}
|
||||
|
||||
## Function to return a Powershell version object from a string
|
||||
@@ -115,4 +154,4 @@ switch ($PSCmdlet.ParameterSetName)
|
||||
'le' { If ( $WindowsBuild -le $le ) { Return $true } Else { Return $false } }
|
||||
'eq' { If ( $WindowsBuild -eq $eq ) { Return $true } Else { Return $false } }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user