Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Powershell脚本块中调用Restmethod URI不起作用_Powershell_Scriptblock - Fatal编程技术网

在Powershell脚本块中调用Restmethod URI不起作用

在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

Scriptblock似乎存在问题,导致它无法处理,我认为这可能是一个简单的语法问题:

        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

我认为您不需要调用表达式(),可以删除它并重试吗?

我认为您不需要调用表达式(),可以删除它并重试吗