gpt4 book ai didi

powershell - PowerShell Set-ItemProperty与点设置属性

转载 作者:行者123 更新时间:2023-12-03 00:17:56 26 4
gpt4 key购买 nike

我正在尝试使用PowerShell(版本2)设置例如ApplicationPool的属性。
(如果有的话,我有一台Windows 7 64位计算机)

我看到this example使用Set-ItemProperty,而this example使用点.设置对象/元素的属性:

$pool | Set-ItemProperty -Name "managedRuntimeVersion" -Value "v4.0"

与:
$pool.managedRuntimeVersion = "v4.0"

那有什么区别呢?我认为第二个更具可读性,但是我不知道这意味着什么。

编辑:
我注意到(至少在这种情况下)存在差异, Set-ItemProperty确实直接保存了属性的值,而另一种方法确实设置了该值(在调试时),但此后没有保存。我还不知道为什么会这样。 (是否需要调用诸如save或commit之类的东西?)请参见 @moonstom的答案,因为Powershell 2.0 Set-ItemProperty是Powershell 3+( see sample)的唯一方法或 $pool | Set-Item

最佳答案

您正在处理该应用程序池的表示形式。如果检查该对象的类型,将获得一个配置元素。因此,设置完之后,您需要使用PS 3.0及更高版本中的$pool | Set-Item将设置推回去。否则,您唯一的选择是Set-ItemProperty

关于powershell - PowerShell Set-ItemProperty与点设置属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29016758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com