Last active
August 29, 2015 14:26
-
-
Save RafPe/77d2ff28f7a0014bf0f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function which allows for quick set/get of app pool property - make sure you have the newest one :) | |
# available @ https://gist.github.com/RafPe/77d2ff28f7a0014bf0f1 | |
function Invoke-AppPoolSetting | |
{ | |
<# | |
.SYNOPSIS | |
Gets or sets application pool setting | |
.PARAMETER appPoolName | |
Defines which application pool we are working with (name is the unique key). By not specyfing this fields we get | |
automatically default app pool selected | |
.PARAMETER propertyName | |
This is property we are interested with | |
.PARAMETER action | |
Defines action which we want to take against property. Possible values are 'get','set' | |
.PARAMETER value | |
Defines value which should be applied to property (applicable only if action is set ) | |
.DESCRIPTION | |
This single line command allows for setting or getting parameter value for choosen application pool. | |
.EXAMPLE | |
Invoke-AppPoolSetting -propertyName queueLength -action get; | |
.EXAMPLE | |
Invoke-AppPoolSetting -propertyName queueLength -action set -value 1234 | |
#> | |
param | |
( | |
[string]$appPoolName, | |
[Parameter(Mandatory=$true)] | |
[ValidateNotNullOrEmpty()] | |
$propertyName, | |
[Parameter(Mandatory=$true)] | |
[ValidateSet('get','set')] | |
[string]$action, | |
$value | |
) | |
#Mapping of namespace (works on IIS 8.5) | |
$NamespaceMapping = @{ | |
name = 'system.applicationHost/applicationPools/{0}' | |
queueLength = 'system.applicationHost/applicationPools/{0}'; | |
autoStart = 'system.applicationHost/applicationPools/{0}'; | |
enable32BitAppOnWin64 = 'system.applicationHost/applicationPools/{0}'; | |
managedRuntimeVersion = 'system.applicationHost/applicationPools/{0}'; | |
managedRuntimeLoader = 'system.applicationHost/applicationPools/{0}'; | |
enableConfigurationOverride = 'system.applicationHost/applicationPools/{0}'; | |
managedPipelineMode = 'system.applicationHost/applicationPools/{0}'; | |
CLRConfigFile = 'system.applicationHost/applicationPools/{0}'; | |
passAnonymousToken = 'system.applicationHost/applicationPools/{0}'; | |
startMode = 'system.applicationHost/applicationPools/{0}'; | |
identityType = 'system.applicationHost/applicationPools/{0}/processModel'; | |
userName = 'system.applicationHost/applicationPools/{0}/processModel'; | |
password = 'system.applicationHost/applicationPools/{0}/processModel'; | |
loadUserProfile = 'system.applicationHost/applicationPools/{0}/processModel'; | |
setProfileEnvironment = 'system.applicationHost/applicationPools/{0}/processModel'; | |
logonType = 'system.applicationHost/applicationPools/{0}/processModel'; | |
manualGroupMembership = 'system.applicationHost/applicationPools/{0}/processModel'; | |
idleTimeout = 'system.applicationHost/applicationPools/{0}/processModel'; | |
idleTimeoutAction = 'system.applicationHost/applicationPools/{0}/processModel'; | |
maxProcesses = 'system.applicationHost/applicationPools/{0}/processModel'; | |
shutdownTimeLimit = 'system.applicationHost/applicationPools/{0}/processModel'; | |
startupTimeLimit = 'system.applicationHost/applicationPools/{0}/processModel'; | |
pingingEnabled = 'system.applicationHost/applicationPools/{0}/processModel'; | |
pingInterval = 'system.applicationHost/applicationPools/{0}/processModel'; | |
pingResponseTime = 'system.applicationHost/applicationPools/{0}/processModel'; | |
disallowOverlappingRotation = 'system.applicationHost/applicationPools/{0}/recycling'; | |
disallowRotationOnConfigChange = 'system.applicationHost/applicationPools/{0}/recycling'; | |
logEventOnRecycle = 'system.applicationHost/applicationPools/{0}/recycling'; | |
memory = 'system.applicationHost/applicationPools/{0}/recycling/periodicRestart'; | |
privateMemory = 'system.applicationHost/applicationPools/{0}/recycling/periodicRestart'; | |
requests = 'system.applicationHost/applicationPools/{0}/recycling/periodicRestart'; | |
time = 'system.applicationHost/applicationPools/{0}/recycling/periodicRestart'; | |
schedule = 'system.applicationHost/applicationPools/{0}/recycling/periodicRestart/schedule'; | |
loadBalancerCapabilities = 'system.applicationHost/applicationPools/{0}/failure'; | |
orphanWorkerProcess = 'system.applicationHost/applicationPools/{0}/failure'; | |
orphanActionExe = 'system.applicationHost/applicationPools/{0}/failure'; | |
orphanActionParams = 'system.applicationHost/applicationPools/{0}/failure'; | |
rapidFailProtection = 'system.applicationHost/applicationPools/{0}/failure'; | |
rapidFailProtectionInterval = 'system.applicationHost/applicationPools/{0}/failure'; | |
rapidFailProtectionMaxCrashes = 'system.applicationHost/applicationPools/{0}/failure'; | |
autoShutdownExe = 'system.applicationHost/applicationPools/{0}/failure'; | |
autoShutdownParams = 'system.applicationHost/applicationPools/{0}/failure'; | |
limit = 'system.applicationHost/applicationPools/{0}/cpu'; | |
action = 'system.applicationHost/applicationPools/{0}/cpu'; | |
resetInterval = 'system.applicationHost/applicationPools/{0}/cpu'; | |
smpAffinitized = 'system.applicationHost/applicationPools/{0}/cpu'; | |
smpProcessorAffinityMask = 'system.applicationHost/applicationPools/{0}/cpu'; | |
smpProcessorAffinityMask2 = 'system.applicationHost/applicationPools/{0}/cpu'; | |
processorGroup = 'system.applicationHost/applicationPools/{0}/cpu'; | |
numaNodeAssignment = 'system.applicationHost/applicationPools/{0}/cpu'; | |
numaNodeAffinityMode = 'system.applicationHost/applicationPools/{0}/cpu'; | |
} | |
# Create target app pool name | |
if( [string]::IsNullOrEmpty($appPoolName) -or $appPoolName -eq 'applicationPoolDefaults' ) { $targetAppName = 'applicationPoolDefaults' } else { $targetAppName = [string]::Format("add[@name='{0}']",$appPoolName ) } | |
switch ($action) | |
{ | |
'get' { | |
Write-Debug "using $targetAppName as target name" | |
# gets value | |
try | |
{ | |
Write-Debug "Requesting property $propertyName value for appPool $appPoolName" | |
$res = (Get-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter $( $NamespaceMapping[ $propertyName ] -f $targetAppName ) -name $propertyName) | |
Write-Debug "property is type of $($res.GetType().Name)" | |
#We need to distinguish from simple value type to complex value types | |
if ( $res.GetType().Name -eq 'ConfigurationAttribute') | |
{ | |
return $res.Value.ToString() | |
} | |
else | |
{ | |
return $res.ToString() | |
} | |
} | |
catch | |
{ | |
Throw "Could not retrieve property $propertyName for appPool $Name" | |
} | |
} | |
'set' { | |
if($null -eq $value) | |
{ | |
Throw 'Please ensure that value is specified for set and is not NULL' | |
} | |
try | |
{ | |
Write-Debug "Setting property $propertyName with value $value for appPool $Name" | |
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter $( $NamespaceMapping[ $propertyName ] -f $targetAppName ) -name $propertyName -Value $value | |
} | |
catch | |
{ | |
Throw "Could not set property $propertyName with value $value for appPool $Name" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment