在Powershell脚本块中调用Restmethod URI不起作用
Scriptblock似乎存在问题,导致它无法处理,我认为这可能是一个简单的语法问题:在Powershell脚本块中调用Restmethod URI不起作用,powershell,scriptblock,Powershell,Scriptblock,Scriptblock似乎存在问题,导致它无法处理,我认为这可能是一个简单的语法问题: function start-wait4 { $scroll = "/-\|/-\|" $idx = 0 $job = Invoke-Command -ComputerName $env:ComputerName -ScriptBlock { Invoke-Expression (Invoke-RestMethod -Uri "https://w
function start-wait4 {
$scroll = "/-\|/-\|"
$idx = 0
$job = Invoke-Command -ComputerName $env:ComputerName -ScriptBlock { Invoke-Expression (Invoke-RestMethod -Uri "https://webaddresswherecodeishosted") } -AsJob
$origpos = $host.UI.RawUI.CursorPosition
$origpos.Y += 1
while (($job.State -eq "Running") -and ($job.State -ne "NotStarted")) {
$host.UI.RawUI.CursorPosition = $origpos
Write-Host $scroll[$idx] -NoNewline
$idx++
if ($idx -ge $scroll.Length) {
$idx = 0
}
Start-Sleep -Milliseconds 100
}
# It's over - clear the activity indicator.
$host.UI.RawUI.CursorPosition = $origpos
Write-Host ' '
}
start-wait4
Start-wait4应开始处理远程脚本并显示旋转等待符号,但失败。问题实际上是InvokeCommand部分,需要更改以启动作业:
function start-wait4 {
$scroll = "/-\|/-\|"
$idx = 0
$job = Start-Job -ScriptBlock { Invoke-Expression (Invoke-RestMethod -Uri "https://webaddresswithremotecode") }
$origpos = $host.UI.RawUI.CursorPosition
$origpos.Y += 1
while (($job.State -eq "Running") -and ($job.State -ne "NotStarted")) {
$host.UI.RawUI.CursorPosition = $origpos
Write-Host $scroll[$idx] -NoNewline
$idx++
if ($idx -ge $scroll.Length) {
$idx = 0
}
Start-Sleep -Milliseconds 100
}
# It's over - clear the activity indicator.
$host.UI.RawUI.CursorPosition = $origpos
Write-Host ' '
}
start-wait4
实际上,问题出在InvokeCommand部分,需要更改以启动作业:
function start-wait4 {
$scroll = "/-\|/-\|"
$idx = 0
$job = Start-Job -ScriptBlock { Invoke-Expression (Invoke-RestMethod -Uri "https://webaddresswithremotecode") }
$origpos = $host.UI.RawUI.CursorPosition
$origpos.Y += 1
while (($job.State -eq "Running") -and ($job.State -ne "NotStarted")) {
$host.UI.RawUI.CursorPosition = $origpos
Write-Host $scroll[$idx] -NoNewline
$idx++
if ($idx -ge $scroll.Length) {
$idx = 0
}
Start-Sleep -Milliseconds 100
}
# It's over - clear the activity indicator.
$host.UI.RawUI.CursorPosition = $origpos
Write-Host ' '
}
start-wait4
我认为您不需要调用表达式(),可以删除它并重试吗?我认为您不需要调用表达式(),可以删除它并重试吗