使用 powershell 和 env 变量打开程序文件目录
Open program files directory using powershell and env variable
我的目标是创建一个 PowerShell 脚本,它将在 Windows 资源管理器中打开特定目录。
有些目录可以通过环境变量引用。
但是我遇到了以下命令的问题
ii %programfiles(x86)%
执行returns出现如下错误:
The term 'x86\' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:23
+ ii %programfiles\(x86\ <<<< )%
+ CategoryInfo : ObjectNotFound: (x86\:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
你能帮我解释一下,我做错了什么吗?
%variable%
是批处理符号。在 PowerShell 中,您必须使用 $env:
来访问环境变量。
Invoke-Item ${env:ProgramFiles(x86)}
大括号是必需的,因为没有它们,括号将不会被识别为变量名的一部分。
我的目标是创建一个 PowerShell 脚本,它将在 Windows 资源管理器中打开特定目录。
有些目录可以通过环境变量引用。
但是我遇到了以下命令的问题
ii %programfiles(x86)%
执行returns出现如下错误:
The term 'x86\' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:23
+ ii %programfiles\(x86\ <<<< )%
+ CategoryInfo : ObjectNotFound: (x86\:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
你能帮我解释一下,我做错了什么吗?
%variable%
是批处理符号。在 PowerShell 中,您必须使用 $env:
来访问环境变量。
Invoke-Item ${env:ProgramFiles(x86)}
大括号是必需的,因为没有它们,括号将不会被识别为变量名的一部分。