Powershell %温度%etc不工作
我有以下文件,用作启动powershell的批处理文件(太长,无法查看,但在另一个脚本中使用) 无论如何,我注意到%systemroot%\temp和%systemroot%不起作用 你知道我该怎么解决这个问题吗Powershell %温度%etc不工作,powershell,Powershell,我有以下文件,用作启动powershell的批处理文件(太长,无法查看,但在另一个脚本中使用) 无论如何,我注意到%systemroot%\temp和%systemroot%不起作用 你知道我该怎么解决这个问题吗 %systemroot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File %SystemRoot%\TEMP\ROFS\testing_script_log.ps1
%systemroot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File %SystemRoot%\TEMP\ROFS\testing_script_log.ps1
谢谢,如果您是从PowerShell而不是从CMD执行该行,则可以使用PowerShell环境变量语法:
PS C:\> & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe"
您可以使用[Environment]::ExpandEnvironmentVariables以老式方式在字符串中展开环境变量
$s = '%systemroot%\temp'
[Environment]::ExpandEnvironmentVariables($s)
已使用以下代码C成功验证。 //文件位置-用户变量 字符串fileLocation=Environment.GetEnvironmentVariable(“AZURE_文件_路径”,EnvironmentVariableTarget.User); //文件位置-系统变量 字符串fileLocation=Environment.GetEnvironmentVariable(“AZURE_文件_路径”,EnvironmentVariableTarget.Machine) 关于Powershell脚本
& "D:\Visual_Studio_Workspace\AzureUpload\AzureUpload\bin\Debug\AzureUpload.exe"
AzureUpload.exe--包含上面的代码C#代码作为控制台应用程序(Visual Studio#u Workspace\AzureUpload\AzureUpload\bin\Debug{.exe file location})在我的系统上完成,效果很好。你犯的错误是什么?你的正确的基督徒…我的愚蠢…道路是错误的!!最终会成功的!我也想知道这一点,所以谢谢你的回答。实际的错误是路径不正确-现在已经修复了,但很高兴知道上面的内容。我是个大傻瓜。为什么在行首需要“&”?这对PowerShell 2.0(Windows 2008)很有用,因为“$env.SYSTEMROOT”不起作用,实际上它是
$s=[Environment]::ExpandEnvironmentVariables($s)