【发布时间】:2022-01-22 22:54:17
【问题描述】:
我想在 powershell 中调用 shutdown.exe 可执行文件,它位于 C:\WINDOWS\System32\shutdown.exe。
由于我们已经在变量$env:windir 中获得了C:\WINDOWS,我只想使用它并将路径的其余部分连接到命令中。我正在尝试这个:
PS C:\Users\shina> .\$env:windir\System32\shutdown.exe -s
但我收到以下错误:
.\$env:windir\System32\shutdown.exe: The term '.\$env:windir\System32\shutdown.exe' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
我怎样才能做到这一点?
【问题讨论】:
-
将
&放在开头而不是 DOT 后跟完整路径 -
这应该可以。只删除环境变量前的 `.\`;它已经包含该文件夹的路径。
标签: powershell