The command:
appcmd lock config -section:...
Will lock the specified config section. But I need to check if the config section is locked or not.
Is there any possible way to do that? Thanks for any reply!
The command:
appcmd lock config -section:...
Will lock the specified config section. But I need to check if the config section is locked or not.
Is there any possible way to do that? Thanks for any reply!
I know this is a few years old now but I was searching for this for Puppet so here's what I came up with.
The command Get-WebConfigurationLock shows if any locks exist on the config section.
E.g. to check the IIS global config section for system.webServer/security/ipSecurity:
Get-WebConfigurationLock -PSPath "IIS:\" -Filter //system.webServer/security/ipSecurity
If the section is unlocked the above command will return null. e.g. to "unlock if locked":
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 can be used instead of appcmd, I favoured appcmd because you can pass lock/unlock as a parameter rather than changing the command itself.
Not sure what Chef looks like though here's the puppet define I've created to unlock/lock sections for reference: https://gist.github.com/krutisfood/d59b3a5c62f6123bf553
For reference I found this Stack Overflow link Programmatically unlocking IIS configuration sections in Powershell though found that Get-WebConfigurationLock more accurately matched the locked state, even reloading the dll or the powershell window getting the attribute value often show IsLocked false when it was locked. ymmv.