update logging methods and fix Run-LocalInstallScript

This commit is contained in:
2020-09-19 13:27:09 -04:00
parent 267e7a913d
commit bc05958fd0
+8 -9
View File
@@ -25,7 +25,7 @@ If ( !(Test-Path $MSPLogs) )
Function Log Function Log
{ {
param( param(
[Parameter(Mandatory=$true)][string]$Message, [Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$Message,
[Parameter(Mandatory=$false)][switch]$Error, [Parameter(Mandatory=$false)][switch]$Error,
[Parameter(Mandatory=$false)][string]$LogName [Parameter(Mandatory=$false)][string]$LogName
) )
@@ -57,12 +57,12 @@ If ( $Name -and $Type )
$URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1" $URL = "https://dev.emberkom.com/emberkom/${Type}/raw/branch/master/${Name}.ps1"
Log "Retrieving : ${Name}.ps1" Log "Retrieving : ${Name}.ps1"
Try { $Script = (New-Object Net.WebClient).DownloadString($URL) } Try { $Script = (New-Object Net.WebClient).DownloadString($URL) }
Catch { Log -Message $_.Exception.Message -Error } Catch { $_.Exception.Message | Log -Error }
Try { $ScriptBlock = [Scriptblock]::Create($Script) } Try { $ScriptBlock = [Scriptblock]::Create($Script) }
Catch { Log -Message $_.Exception.Message -Error } Catch { $_.Exception.Message | Log -Error }
Log "Executing: ${Name}.ps1 ${Arguments}" Log "Executing: ${Name}.ps1 ${Arguments}"
Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments } Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments }
Catch { Log -Message $_.Exception.Message -Error } Catch { $_.Exception.Message | Log -Error }
} Else { Log "No script or type was specified" } } Else { Log "No script or type was specified" }
} }
@@ -74,11 +74,10 @@ param(
[Parameter(Mandatory=$true)][string]$Arguments, [Parameter(Mandatory=$true)][string]$Arguments,
[Parameter(Mandatory=$true)][string]$AppName [Parameter(Mandatory=$true)][string]$AppName
) )
If ( $AppName -eq "null" ) { $AppName = $false }
If ( $Arguments -eq "null" ) { $Arguments = $null } If ( $Arguments -eq "null" ) { $Arguments = $null }
If ( Test-Path "${Script}" ) If ( Test-Path "${Script}" )
{ {
If ( $AppName ) If ( $AppName -ne "null" )
{ {
Log "Checking for running instances of ${AppName}" Log "Checking for running instances of ${AppName}"
$RunningInstances = Get-Process | Where { $_.Name -like "${AppName}" } $RunningInstances = Get-Process | Where { $_.Name -like "${AppName}" }
@@ -86,15 +85,15 @@ If ( Test-Path "${Script}" )
{ {
Log "Executing: ${Script} ${Arguments}" Log "Executing: ${Script} ${Arguments}"
Try { Start-Process "${Script}" -ArgumentList "{$Arguments}" -Wait } Try { Start-Process "${Script}" -ArgumentList "{$Arguments}" -Wait }
Catch { Log -Message $_.Exception.Message -Error } Catch { $_.Exception.Message | Log -Error }
} }
Else { Log "${AppName} is currently in use and will not be installed now" } Else { Log "Dependent apps are currently in use and preventing the specified script from running" }
} }
Else Else
{ {
Log "Executing: ${Script} ${Arguments}" Log "Executing: ${Script} ${Arguments}"
Try { Start-Process "${Script}" -ArgumentList "{$Arguments}" -Wait } Try { Start-Process "${Script}" -ArgumentList "{$Arguments}" -Wait }
Catch { Log -Message $_.Exception.Message -Error } Catch { $_.Exception.Message | Log -Error }
} }
} }
Else { Log "The specified script does not exist: ${Script}" } Else { Log "The specified script does not exist: ${Script}" }