code_junkie

Creating an IIS 6.0 Application Pool using Powershell

Nov 12th, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. $AppPoolSettings = [wmiclass]'rootMicrosoftIISv2:IISApplicationPoolSetting'
  2. $NewPool = $AppPoolSettings.CreateInstance()
  3. $NewPool.Name = 'W3SVC/AppPools/MyAppPool'
  4. $Result = $NewPool.Put()
  5.  
  6. # Settings
  7. $newApplication = "MaxSys.Services"
  8. $poolUserName = "BRISBANEsvcMaxSysTest"
  9. $poolPassword = "ThisisforT3sting"
  10.  
  11. $newVDirName = "W3SVC/1/ROOT/" + $newApplication
  12. $newVDirPath = "C:" + $newApplication
  13. $newPoolName = $newApplication + "Pool"
  14.  
  15. #Switch the Website to .NET 2.0
  16. C:windowsMicrosoft.NETFrameworkv2.0.50727aspnet_regiis.exe -sn W3SVC/
  17.  
  18. # Create Application Pool
  19. $appPoolSettings = [wmiclass] "rootMicrosoftIISv2:IISApplicationPoolSetting"
  20. $newPool = $appPoolSettings.CreateInstance()
  21. $newPool.Name = "W3SVC/AppPools/" + $newPoolName
  22. $newPool.PeriodicRestartTime = 0
  23. $newPool.IdleTimeout = 0
  24. $newPool.MaxProcesses = 2
  25. $newPool.WAMUsername = $poolUserName
  26. $newPool.WAMUserPass = $poolPassword
  27. $newPool.AppPoolIdentityType = 3
  28. $newPool.Put()
  29. # Do it again if it fails as there is a bug with Powershell/WMI
  30. if (!$?)
  31. {
  32. $newPool.Put()
  33. }
  34.  
  35. # Create the virtual directory
  36. mkdir $newVDirPath
  37.  
  38. $virtualDirSettings = [wmiclass] "rootMicrosoftIISv2:IIsWebVirtualDirSetting"
  39. $newVDir = $virtualDirSettings.CreateInstance()
  40. $newVDir.Name = $newVDirName
  41. $newVDir.Path = $newVDirPath
  42. $newVDir.EnableDefaultDoc = $False
  43. $newVDir.Put()
  44. # Do it a few times if it fails as there is a bug with Powershell/WMI
  45. if (!$?)
  46. {
  47. $newVDir.Put()
  48. }
  49.  
  50. # Create the application on the virtual directory
  51. $vdir = Get-WmiObject -namespace "rootMicrosoftIISv2" -class "IISWebVirtualDir" -filter "Name = '$newVDirName'"
  52. $vdir.AppCreate3(2, $newPoolName)
  53.  
  54. # Updated the Friendly Name of the application
  55. $newVDir.AppFriendlyName = $newApplication
  56. $newVDir.Put()
Add Comment
Please, Sign In to add comment