Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. Import-Module WebAdministration
  2.  
  3. Function Prepare([string]$name,[int]$port)
  4. {
  5. # create a new directory for the site
  6. md c:inetpubsite$name
  7.  
  8. # create a new application pool
  9. New-WebAppPool "pool$name"
  10.  
  11. # create a new site using the folder and pool we just created
  12. New-WebSite -name "site$name" -port $port -physicalpath "c:inetpubsite$name" -applicationpool "pool$name"
  13.  
  14. # Make sure the pool runs as applicationpoolidentity and loads its user profile
  15. set-webconfigurationproperty -pspath 'machine/webroot/apphost' -filter "system.applicationhost/applicationpools/add[@name='pool$name']/processmodel" -name "identitytype" -value "applicationpoolidentity"
  16. set-webconfigurationproperty -pspath 'machine/webroot/apphost' -filter "system.applicationhost/applicationpools/add[@name='pool$name']/processmodel" -name "loaduserprofile" -value "true"
  17.  
  18. # create two pages, one to show the environment variable, the other to set it.
  19. "<%@ page %><html># <% response.write(system.environment.getenvironmentvariable(`"myvar`")) %> #</html>" | out-file "c:inetpubsite$namedefault.aspx"
  20. "<%@ page %><% system.environment.setenvironmentvariable(`"myvar`", `"i am site $name`", system.environmentvariabletarget.user) %>" | out-file "c:inetpubsite$namesetenv.aspx"
  21.  
  22. # hit the home page, just to get it started
  23. (new-object net.webclient).DownloadString("http://localhost:$port")
  24. # set our environment variable
  25. (new-object net.webclient).DownloadString("http://localhost:$port/setenv.aspx")
  26. # recycle the pool
  27. Restart-WebAppPool -Name "Pool$name"
  28. # wait a little bit to restart
  29. Start-Sleep -Milliseconds 500
  30. # hit the home page again to show our variable
  31. (new-object net.webclient).DownloadString("http://localhost:$port")
  32. }
  33.  
  34. # call the function for two sites
  35. Prepare A 81
  36. Prepare B 82
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement