From bc05958fd093d727cad6148b5cd3cc5ddf662ad0 Mon Sep 17 00:00:00 2001 From: dyoder Date: Sat, 19 Sep 2020 13:27:09 -0400 Subject: [PATCH] update logging methods and fix Run-LocalInstallScript --- Tools.ps1 | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Tools.ps1 b/Tools.ps1 index eae7e63..339595b 100644 --- a/Tools.ps1 +++ b/Tools.ps1 @@ -25,7 +25,7 @@ If ( !(Test-Path $MSPLogs) ) Function Log { param( - [Parameter(Mandatory=$true)][string]$Message, + [Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$Message, [Parameter(Mandatory=$false)][switch]$Error, [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" Log "Retrieving : ${Name}.ps1" Try { $Script = (New-Object Net.WebClient).DownloadString($URL) } - Catch { Log -Message $_.Exception.Message -Error } + Catch { $_.Exception.Message | Log -Error } Try { $ScriptBlock = [Scriptblock]::Create($Script) } - Catch { Log -Message $_.Exception.Message -Error } + Catch { $_.Exception.Message | Log -Error } Log "Executing: ${Name}.ps1 ${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" } } @@ -74,11 +74,10 @@ param( [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 ) + If ( $AppName -ne "null" ) { Log "Checking for running instances of ${AppName}" $RunningInstances = Get-Process | Where { $_.Name -like "${AppName}" } @@ -86,15 +85,15 @@ If ( Test-Path "${Script}" ) { Log "Executing: ${Script} ${Arguments}" 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 { Log "Executing: ${Script} ${Arguments}" 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}" }