PowerShell脚本不会将$ PSDEFAULTPARAMETERVALUE添加到$ profile
我正在编写一个快速的PowerShell脚本以导入模块并更新各种计算机上的一些默认参数。我遇到了一个问题,当我在脚本中添加 $ PSDEFAULTPARAMETERVALUES
到$ profile时,它将更改为 system.management.automation.defaultParameterDictionary
,然后引发了一个错误不被认为是cmdlet的名称。
中的代码
这是我的PS1脚本 add -content -path $ profile -value
“ $ psdefaultParametervalues = @{}” 以下是添加到profile
system.manage.automation.automation.defaultparameterdictionarydictionary dictionary dictionary dictionary = @{}
我已经尝试了从使用set-content到使用变量避免引用混乱的所有方法。
感谢您的帮助!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用单语引号
这些是字面字符串,因此任何变量都不会扩展。
Use single quotes
These are literal strings so any variables will not expand.
要添加到 tonypags的帮助答案:
double> double> double> double quoted powershell strings(<代码
“ ...”
)是 expligable strings ,即,它们执行嵌入式变量引用的字符串interpolation 和子表达(例如$(1 + 2)
)因此,自动
$ PSDEFAULTPARAMETERVALUE
变量在您的“ ...”中扩展了
字符串,这本质上意味着它被其.toString()表示 - 在这种情况下,这仅是变量值的类型名称。
如果您的全部字符串被用来使用 verbatim ,请使用
'...'...'
引用,如Tonypags的答案所示。如果您确实需要扩展(字符串插值),但需要选择性地抑制 easse
$
$ tarne ,使用`
(backtick),powershell's 逃脱字符,如下所示:To add to tonypags' helpful answer:
Double-quoted PowerShell strings (
"..."
) are expandable strings, i.e they perform string interpolation of embedded variable references (e.g.$PSDefaultParameterValues
) and subexpressions (e.g.$(1 + 2)
)Single-quoted strings (
'...'
) are verbatim strings, i.e. their content is used as-is (verbatim, literally).Thus, the automatic
$PSDefaultParameterValues
variable was expanded in your"..."
string, which in essence means it was replaced with its.ToString()
representation - which in this case is simply the type name of the variable's value.If your entire string is meant to be used verbatim, use
'...'
quoting, as shown in tonypags' answer.If you do need expansions (string interpolation), but need to selectively suppress them, escape
$
characters as`$
, using`
(a backtick), PowerShell's escape character, as shown in the following example: