【问题标题】:Check if configuration section is locked IIS 7检查配置部分是否被锁定 IIS 7
【发布时间】:2013-01-11 09:44:51
【问题描述】:

命令:

appcmd lock config -section:...

将锁定指定的配置部分。但是我需要检查配置部分是否被锁定。

有没有办法做到这一点?感谢您的回复!

【问题讨论】:

  • 我对@9​​87654322@不熟悉,但是当config对象类型被锁定时,是否有一个列表命令或类似的命令不会改变任何东西,当配置被锁定时会被拒绝并在解锁时允许?
  • 嗨,你有没有找到解决这个问题的方法?我有同样的问题 - 我只想在它被锁定时运行解锁(厨师)

标签: iis batch-file


【解决方案1】:

我知道这已经有几年了,但我正在为 Puppet 寻找这个,所以这就是我想出的。

Get-WebConfigurationLock 命令显示配置部分是否存在任何锁。

例如检查 IIS 全局配置部分的 system.webServer/security/ipSecurity:

Get-WebConfigurationLock -PSPath "IIS:\" -Filter //system.webServer/security/ipSecurity

如果该部分已解锁,上述命令将返回 null。例如“如果锁定则解锁”:

if (Get-WebConfigurationLock -PSPath "IIS:\" -Filter //system.webServer/security/ipSecurity)  {
    %windir%/System32/inetsrv/appcmd.exe unlock config -section:system.webServer/security/ipSecurity
} else {
    Write-Host "Already unlocked"
}

可以使用 Remove-WebConfigurationLock 代替 appcmd,我更喜欢 appcmd,因为您可以将 lock/unlock 作为参数传递,而不是更改命令本身。

不确定 Chef 是什么样的,尽管这是我创建的用于解锁/锁定部分以供参考的 puppet 定义: https://gist.github.com/krutisfood/d59b3a5c62f6123bf553

作为参考,我发现这个 Stack Overflow 链接Programmatically unlocking IIS configuration sections in Powershell 虽然发现 Get-WebConfigurationLock 更准确地匹配锁定状态,即使重新加载 dll 或获取属性值的 powershell 窗口在锁定时也经常显示 IsLocked false。 ymmv。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多