我有一个名为file.ps1的文件,其代码如下:
$varsent=$args[0]
echo $varsent当我试图用以下命令调用这个ps1文件时,因为我需要以提升的权限执行ps1:
$var = "test"
Start-Process powershell -ArgumentList '-noprofile -file "\\network path with spaces\file.ps1" $var ' -verb RunAs结果是"$var“而不是"test”。
但是有了
Start-Process powershell -ArgumentList '-noprofile -file "\\network path with spaces\file.ps1" test ' -verb RunAs结果是单词“测试”
我认为问题在于,在执行代码时,$var没有被它的值所取代,但我不知道为什么。拜托你能帮帮我吗?我必须使用$var。
发布于 2020-05-09 05:03:42
因为$var不是在单引号字符串中解释的,所以请尝试:
$var = "test"
Start-Process powershell -ArgumentList "-noprofile -file \\path\file.ps1 $var " -verb RunAs有空格:
Start-Process powershell -ArgumentList "-noprofile -file `"C:\temp\Un petit test.ps1`" $var" -verb RunAs“允许您在""中使用"。
https://stackoverflow.com/questions/61691889
复制相似问题