从CMD.exe调用Powershell时,Invoke-RestMethod失败

时间:2016-08-25 17:03:48

标签: rest powershell batch-file cmd

我有两个Powershell脚本可以很好地协同工作:

  • =IF(ISBLANK(B2),"",CONCATENATE("ABC",TEXT(ROW(1:1),"000000"))) 脚本,它接受运行Method的参数。
  • Invoke-RestMethod脚本,将参数发送到Caller

Method中,我定义参数并发送它们:

Caller

$file = "\\Share\Location\STUDENTS.txt" $username = "d155a9dd-be60-9dcb-9009-02d634192545" $type = "person" $operation = "refresh" & "\\Share\Location\Batch\method.ps1" $file $username $type $operation 中,我回显变量并显示响应,对于以下输出:

Method

到目前为止,这么好。现在,我需要将FILE: \\Share\Location\STUDENTS.txt USER: d155a9dd-be60-9dcb-9009-02d634192545 TYPE: person OPER: refresh Success: Feed File Uploaded. Use the reference code 53a7c62c7f4a412889af3b15d712525b to track these records in the logs. 改为Windows批处理文件,以便在调用Caller时绕过执行策略。我无法使用Method参数,因为Windows 10在命令行中不支持UNC路径,所以我改为使用-File参数:

-Command

但我从THAT脚本得到的输出是:

@ECHO OFF    
SET feedfile='\\Share\Location\STUDENTS.txt'
SET integration='d155a9dd-be60-9dcb-9009-02d634192545'
SET datatype='person'
SET action='refresh'

SET pscommand="& '\\Share\Location\Batch\method.ps1' %feedfile% %integration% %datatype% %action%"
PowerShell -NoProfile -ExecutionPolicy Bypass -Command %pscommand%

在任何一种情况下都会发送相同的Web请求 - 它与批处理文件一起失败,但与Powershell脚本完美配合。问题是什么?

0 个答案:

没有答案