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) {
'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) }
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' {
Write-Output "Executing: ${Path} ${Arguments}"