Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. $appCmdPath = "$env:SystemRoot\system32\inetsrv\appcmd.exe"
  2. $webApplicationName = "Amc76.Web";
  3. $iteration = "0.1"
  4. $applicationPoolName = $webApplicationName + $iteration;
  5.  
  6. function Test-ApplicationPool([string]$appPoolName)
  7. {
  8. $appPool = . $appCmdPath list apppools $appPoolName
  9. return $appPool -ne $null
  10. }
  11.  
  12. function Set-ApplicationPoolIdentity([string]$appPoolName, [string]$username, [string]$password)
  13. {
  14. $processModel = "/[name='$appPoolName'].processModel"
  15. $identityParam = "$processModel.identityType:$identityType"
  16. $usernameParam = "$processModel.username:$username"
  17. $passwordParam = "$processModel.password:$password"
  18.  
  19. . $appCmdPath set config /section:applicationPools $identityParam $usernameParam $passwordParam
  20. }
  21.  
  22. function Get-ApplicationPool([ValidateNotNullOrEmpty()][string]$appPoolName)
  23. {
  24. return . $appCmdPath list apppool $appPoolName
  25. }
  26.  
  27. function Get-ApplicationPoolIdentity([string]$appPoolName)
  28. {
  29. if (Test-ApplicationPool -appPoolName $appPoolName -eq $true)
  30. {
  31. $processModelXPath = "/system.applicationHost/applicationPools/add[@name='$appPoolName']/processModel"
  32.  
  33. $processModel = "/[name='$appPoolName']"
  34. $appPools = [xml] (. $appCmdPath list config /section:applicationPools)
  35. $appPool = $appPools.DocumentElement.SelectSingleNode($processModelXPath)
  36. if ($appPool -ne $null)
  37. {
  38. $object = New-Object –TypeName PSObject
  39. $object |
  40. Add-Member –MemberType NoteProperty –Name IdentityType –Value $appPool.identityType –PassThru |
  41. Add-Member –MemberType NoteProperty –Name Username –Value $appPool.userName –PassThru |
  42. Add-Member –MemberType NoteProperty –Name Password –Value $appPool.password
  43. return $object
  44. }
  45. }
  46. return $null;
  47. }
  48.  
  49. function New-ApplicationPool
  50. {
  51. Param(
  52. [Parameter(Mandatory=$true)]
  53. [ValidateNotNullOrEmpty()]
  54. $Name,
  55. [Parameter(Mandatory=$true)]
  56. [ValidateNotNullOrEmpty()]
  57. [ValidateSet("v4.0","v2.0","None")]
  58. $ManagedRuntimeVersion,
  59. [Parameter(Mandatory=$true)]
  60. [ValidateNotNullOrEmpty()]
  61. [ValidateSet("Integrated","Classic")]
  62. $ManagedPipelineMode,
  63. [Parameter(Mandatory=$true)]
  64. [ValidateNotNullOrEmpty()]
  65. [ValidateSet("OnDemand","AlwaysRunning")]
  66. $StartMode
  67. )
  68.  
  69. if (Test-ApplicationPool -appPoolName $Name) {
  70. Write-Warning "Application Pool already exists."
  71. return;
  72. }
  73.  
  74. $runtimeVersion = $ManagedRuntimeVersion
  75.  
  76. if ($ManagedRuntimeVersion -eq "None") {
  77. $runtimeVersion = "";
  78. }
  79.  
  80. . $appCmdPath add apppool /name:$Name /managedRuntimeVersion:$runtimeVersion /managedPipelineMode:$ManagedPipelineMode /startMode:$StartMode
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement