source external scripts that have no arguments instead of running in scriptblock

This commit is contained in:
2024-06-24 17:06:45 -04:00
parent c753b13f1e
commit 6c27d5fa18
+8 -3
View File
@@ -138,14 +138,19 @@ Function Run-Script {
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
'live-ps' { 'live-ps' {
Write-Output "Retrieving : ${LivePSScript}.ps1" Write-Output "Retrieving : ${LivePSScript}.ps1"
Try { $Script = (New-Object Net.WebClient).DownloadString($URL) } If ( $null -eq $Arguments ) {
Catch { Write-Error $_.Exception.Message ; Exit } $ScriptFile = Download-File -URL $URL
Try { $ScriptBlock = [Scriptblock]::Create($Script) } 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 } Catch { Write-Error $_.Exception.Message ; Exit }
Write-Output "Executing: ${LivePSScript}.ps1 ${Arguments}" Write-Output "Executing: ${LivePSScript}.ps1 ${Arguments}"
Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments } Try { Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $Arguments }
Catch { Write-Error $_.Exception.Message ; Exit } Catch { Write-Error $_.Exception.Message ; Exit }
} }
}
'local' { 'local' {
Write-Output "Executing: ${Path} ${Arguments}" Write-Output "Executing: ${Path} ${Arguments}"