Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $appCmdPath = "$env:SystemRoot\system32\inetsrv\appcmd.exe"
- $webApplicationName = "Amc76.Web";
- $iteration = "0.1"
- $applicationPoolName = $webApplicationName + $iteration;
- function Test-ApplicationPool([string]$appPoolName)
- {
- $appPool = . $appCmdPath list apppools $appPoolName
- return $appPool -ne $null
- }
- function Set-ApplicationPoolIdentity([string]$appPoolName, [string]$username, [string]$password)
- {
- $processModel = "/[name='$appPoolName'].processModel"
- $identityParam = "$processModel.identityType:$identityType"
- $usernameParam = "$processModel.username:$username"
- $passwordParam = "$processModel.password:$password"
- . $appCmdPath set config /section:applicationPools $identityParam $usernameParam $passwordParam
- }
- function Get-ApplicationPool([ValidateNotNullOrEmpty()][string]$appPoolName)
- {
- return . $appCmdPath list apppool $appPoolName
- }
- function Get-ApplicationPoolIdentity([string]$appPoolName)
- {
- if (Test-ApplicationPool -appPoolName $appPoolName -eq $true)
- {
- $processModelXPath = "/system.applicationHost/applicationPools/add[@name='$appPoolName']/processModel"
- $processModel = "/[name='$appPoolName']"
- $appPools = [xml] (. $appCmdPath list config /section:applicationPools)
- $appPool = $appPools.DocumentElement.SelectSingleNode($processModelXPath)
- if ($appPool -ne $null)
- {
- $object = New-Object –TypeName PSObject
- $object |
- Add-Member –MemberType NoteProperty –Name IdentityType –Value $appPool.identityType –PassThru |
- Add-Member –MemberType NoteProperty –Name Username –Value $appPool.userName –PassThru |
- Add-Member –MemberType NoteProperty –Name Password –Value $appPool.password
- return $object
- }
- }
- return $null;
- }
- function New-ApplicationPool
- {
- Param(
- [Parameter(Mandatory=$true)]
- [ValidateNotNullOrEmpty()]
- $Name,
- [Parameter(Mandatory=$true)]
- [ValidateNotNullOrEmpty()]
- [ValidateSet("v4.0","v2.0","None")]
- $ManagedRuntimeVersion,
- [Parameter(Mandatory=$true)]
- [ValidateNotNullOrEmpty()]
- [ValidateSet("Integrated","Classic")]
- $ManagedPipelineMode,
- [Parameter(Mandatory=$true)]
- [ValidateNotNullOrEmpty()]
- [ValidateSet("OnDemand","AlwaysRunning")]
- $StartMode
- )
- if (Test-ApplicationPool -appPoolName $Name) {
- Write-Warning "Application Pool already exists."
- return;
- }
- $runtimeVersion = $ManagedRuntimeVersion
- if ($ManagedRuntimeVersion -eq "None") {
- $runtimeVersion = "";
- }
- . $appCmdPath add apppool /name:$Name /managedRuntimeVersion:$runtimeVersion /managedPipelineMode:$ManagedPipelineMode /startMode:$StartMode
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement