From 6c27d5fa184d07ecae2cd802a7e440600b38e6e1 Mon Sep 17 00:00:00 2001 From: David Yoder Date: Mon, 24 Jun 2024 17:06:45 -0400 Subject: [PATCH] source external scripts that have no arguments instead of running in scriptblock --- Tools.ps1 | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Tools.ps1 b/Tools.ps1 index 41a4cbb..b28c68d 100644 --- a/Tools.ps1 +++ b/Tools.ps1 @@ -138,13 +138,18 @@ Function Run-Script { switch ($PSCmdlet.ParameterSetName) { 'live-ps' { Write-Output "Retrieving : ${LivePSScript}.ps1" - Try { $Script = (New-Object Net.WebClient).DownloadString($URL) } - Catch { Write-Error $_.Exception.Message ; Exit } - Try { $ScriptBlock = [Scriptblock]::Create($Script) } - Catch { Write-Error $_.Exception.Message ; Exit } - Write-Output "Executing: ${LivePSScript}.ps1 ${Arguments}" - Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments } - Catch { Write-Error $_.Exception.Message ; Exit } + If ( $null -eq $Arguments ) { + $ScriptFile = Download-File -URL $URL + Write-Output "Sourcing: ${LivePSScript}.ps1" + . $ScriptFile + If ( Test-Path $ScriptFile ) { Remove-Item $ScriptFile -Force -ErrorAction SilentlyContinue } + } Else { + Try { $ScriptBlock = [Scriptblock]::Create((New-Object Net.WebClient).DownloadString($URL)) } + Catch { Write-Error $_.Exception.Message ; Exit } + Write-Output "Executing: ${LivePSScript}.ps1 ${Arguments}" + Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments } + Catch { Write-Error $_.Exception.Message ; Exit } + } } 'local' {