KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm in the process of writing some automated scripts to create/update IIS sites on a server using PowerShell. The aim is to have a configuration object that can then be handled by a single script to do all the heavy lifting. My config HashTable looks like this: $config = @{ AppPools = ( @{ Name="AppPool1" Properties = @{ Enable32BitAppOnWin64=$true ManagedRuntimeVersion="v4.0" ProcessModel = @{ IdentityType = "NetworkService" } } } ) Websites = ( @{ Name="Site1" Properties = @{ PhysicalPath = "C:\sites\site1" ApplicationPool = "AppPool1" } } ) } My script then uses the config to process each application pool and web site: Import-Module WebAdministration $config.AppPools | % { $poolPath = "IIS:\AppPools\$($_.Name)" # Create if not exists if(-not(Test-Path $poolPath)){ New-WebAppPool $_.Name } # Update the properties from the config $pool = Get-Item $poolPath Set-PropertiesFromHash $pool $_.Properties $pool | Set-Item } $config.Websites | %{ $sitePath = "IIS:\Sites\$($_.Name)" # Create if not exists if(-not(Test-Path $sitePath)){ New-WebSite $_.Name -HostHeader $_.Name } # Update the properties from the config $site = Get-Item $sitePath Set-PropertiesFromHash $site $_.Properties $site | Set-Item } As you can see the process is virtually identical (apart from the item paths and type being created). This will of course be refactored if I get
Tags (comma-separated)
Save Edits
Cancel