Check if configuration section is locked IIS 7 - iis

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.

Related

How to toggle a feature enable or disable feature in terraform without modifying code

In Terraform we need to implement a functionality to toggle the block of terraform code(From enable to disable) and redeploy without manually changing the terraform code using commenting the code lines. What is the best way without manually change the code?
Regards
Flashnightss
We tried to manually change the code for example disabling the feature(e.g storage replication disable from enable) using /* */ comment lines. But thats not the good idea for a novice users. Looking for a programmatically implement this without modifying the code manually.
One option is to introduce a feature flag, i.e., a variable that tells the code if a feature/module/block should be used, or not.
E.g., assuming you have a variable myfeatureflag declared in your terraform.tfvars and you want optionally use a resource block, you could write
resource "myresource" "myresourceid" {
count = var.myfeatureflag == true ? 1 : 0
<resource-specific code>
}
You could do it similarly for calling complete modules.

Azure Devops logging commands in release pipeline

I am trying to customize the output of my pipeline release through setting some env variables into a task.
I found the following link:
https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=powershell
which however does not seem to work.
What I am doing is simply to create a pipeline with a single task (either bash or PS), and there declaring the commands specified in the link through the inline version of the task.
Has anyone already successfully managed to make these commands work?
Do I do something wrong and/or incomplete?
Does anyone have a better way to customise the pipeline with relevant information from a task? E.g. through the release name, or the description and/or tag of the specific release?
Edit:
Write-Host "##vso[task.setvariable variable=sauce;]crushed tomatoes"
Write-Host "##vso[task.setvariable variable=secretSauce;issecret=true]crushed tomatoes with garlic"
Write-Host "Non-secrets automatically mapped in, sauce is $env:SAUCE"
Write-Host "Secrets are not automatically mapped in, secretSauce is $env:SECRETSAUCE"
Write-Host "You can use macro replacement to get secrets, and they'll be masked in the log: $(secretSauce)"
this is the code, copy and pasted. Now I tried also with the script, and it does not work either.
I use an hosted windows agent.
When you set a new variable with the logging command the variable is available only in the next tasks and not in the same task.
So, split your script to 2 tasks, in the second task put the last 3 lines and you will see that the first task works:
this also puzzled me for a while, in the end i found out that if you want to modify the $env:path you can call the special task called task.prependpath by using the special logging command syntax like "##vso[task.prependpath]local directory path". you can find more of this kind of special commands from their source :
https://github.com/microsoft/azure-pipelines-tasks/blob/master/docs/authoring/commands.md

Find out which process prevents to modify application data files

Sometimes it happens, that some files of my application are used by some processes. For example, user opens application log, or something like that, and forgets to close it. This causes some errors while installing/upgrading/uninstalling. In such cases, I'd like to find out, what process is using file, and show user a message, indicating, that files are used.
Is it possible in Inno Setup to find out, what process prevents script from modifying file? At least, when I'm trying to do this in Code section.
The Inno Setup can automatically check, if the installed files are locked by some processes, and offer a user to close (and restart later) the applications automatically (since 5.5.0).
Make sure the CloseApplications directive is set to its default value yes.
Though by default, only *.exe,*.dll,*.chm files are checked. If you want to check also other or all other files, modify the CloseApplicationsFilter directive:
[Setup]
; default
CloseApplications=yes
; check all files
CloseApplicationsFilter=*.*
If you are installing some files by a code, use the RegisterExtraCloseApplicationsResources event function:
procedure RegisterExtraCloseApplicationsResources;
begin
RegisterExtraCloseApplicationsResource(
False, ExpandConstant('{userappdata}\My Program.log'));
end;

Setting uploadReadAheadSize in IIS 8.5

I'm trying to use the following command to set uploadReadAheadSize in IIS 8.5 on Windows Server 2012 R2:
appcmd.exe set config -section:system.webServer/serverRuntime/uploadReadAheadSize:"491521" /commit:apphost
But I keep getting this error:
ERROR ( message:Can not set attribute "uploadReadAheadSize" to value "491521 "..
Reason: Not a valid unsigned integer . )
From this page the maximum should be 4GB so my integer is valid. (Admittedly this goes back to IIS 6.0 so not sure how relevant it is now.)
This page on the other hand suggests that the property may have been replaced/deprecated or something, but it's not clear from the error message or anything I can find on the Googles.
I'm no expert in IIS so there may be a simple/obvious answer to this, but I'd be grateful if anyone can share some more concrete info...
UPDATE: also posted in IIS forums
Open IIS
Navigate under Default Web Site
Scroll down to Management and open Configuration Editor
Select following section (drop down at the top) system.webServer and expand it, then locate serverRuntime
you'll find there the current value of uploadReadAheadSize value, which you can change
Four years later... The clue was in the error message: "491521 " is not a valid unsigned integer. Note the space at the end of the integer before the quote marks.
Turns out the command I was running had a double space between the value and the /commit. Change to a single space and the command works fine.
Interestingly it's the same command I've been using for years and I've just confirmed it still works fine with the double space in Server 2008 R2!
How to set the maxAllowedContentLength to 500MB while running on IIS7?
Try this. Looks like you need to set it below 4294967295(in bytes)
Try this:
appcmd.exe set config -section:system.webServer/serverRuntime /uploadReadAheadSize:"491521" /commit:apphost
There must be a space after -section:system.webServer/serverRuntime and before /uploadReadAheadSize .
WebServer Run Time
POWERSHELL Command
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.webServer/serverRuntime" -name "uploadReadAheadSize" -value 2147483647
uploadReadAheadSize Optional uint attribute.
Specifies the number of bytes that a Web server will read into a buffer and pass to an ISAPI extension or module. This occurs once per client request. The ISAPI extension or module receives any additional data directly from the client. The value must be between 0 and 2147483647.
The default value is 49152.

Powershell: commandline applications not working after calling method from module

I have created a powershell module (.psm1) file that includes a few other powershell scripts. We use it for sharepoint.
So basically, here's what happens:
I have a deploy script that retrieves the module location from the registry
It loads the module using the Import-Module cmdlet (using -force switch)
This module in turn loads the Sharepoint 2010 snap in and a few other scripts that I created
It runs runs a deployment script that references functions from the included scripts
It also runs a command line application and sends the output directly to the screen
The script will usually work the first time. However, after a few number of tries the commandline tool will stop working and sending output to the screen altogether. And if I try to run a commandline tool (not a cmd-let) after running my script, it don't worky anymore: no output, nothing is done. Its just the same as hitting enter on a blank prompt. anything powershell specific or running GUI applications will work fine but running any console application will not produce any concievable results. the only solution to this, is to just close my powershell and open it again. it will work for usually once and I will have to close it again. our users certainly wont be happy about that..
The most 'notable' things on the script:
scriptblocks are used extensively (for logging), a script block is sent to a handler that executes it using invokecommand and logs the step
its manipulating sharepoint objects
all objects are properly disposed of
no static variables are created nor changed
There are a few global variables shared across all scripts
What I have tried:
I striped my code to a bare minimum: loading an xml file, and restaring a few windows services but I'm still getting this intermittently. I have no idea which part of the code could cause this. I would love to post the code, but our company policy forbids me to. so my aplogies..
Update as per the comment below:
here's roughly how I use codeblocks. I have this function below that is used everytime I want to make the user aware of a task that I'm executing and what it outcome is.
function DoTask($someString, $scriptBlock, $param)
{
try
{
OutputTaskDescription $someString
InvokeCommand $scriptBlock -ArgumentList $param
OutputResultOK
}
catch
{
OutputResultError $_.tostring()
}
}
it could then be used like this:
$stringVar = "something"
$SpSite = new-spsite
deploySomething 'Deploying something' -param $spsite -ScriptBlock {
dosomethingToObject $stringvar
dosomethingToObject $spSite.Name
}
it would then output something like:
Deploying Something ------------- OK
Deploying Something ------------- ERROR
Also notice that I pass the $spsite in the argument list and I just use the string directly. I still don't understand how this works but it seems like I can access all primitive typed variables even without passing them as arguments but I have to pass more complex objects are params, else they dont have any value.
Update:
after much searching and days of pain. I have found others with the same pain. My code exhibits the same exact symptoms as described here:
http://connect.microsoft.com/PowerShell/feedback/details/496326/stability-problem-any-application-run-fails-with-lastexitcode-1073741502
I guess there is no solution yet to this problem.
After a little while I've noticed that if I've ran some very memory intensive functions, I too have gotten that behavior where everything you try to execute just goes to the prompt again. I'd recommend setting Set-PsDebug -Trace 2 to see what those functions are actually doing. I fixed my issue by doing this and figuring out how to make my functions more efficient.

Resources