$basedir = "C:\inetpub\" $baseweb = "IIS:\Sites\" $basepool = "IIS:\AppPools\" $sqlinstance = "." $Shares=[WMICLASS]”WIN32_Share” Import-Module WebAdministration [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null $sqlserver = New-Object Microsoft.SqlServer.Management.Smo.Server($sqlinstance) Add-Type -Path (Join-Path -Path (Split-Path $script:MyInvocation.MyCommand.Path) -ChildPath 'CubicOrange.Windows.Forms.ActiveDirectory.dll') $DialogPicker = New-Object CubicOrange.Windows.Forms.ActiveDirectory.DirectoryObjectPickerDialog $DialogPicker.DefaultLocations = [CubicOrange.Windows.Forms.ActiveDirectory.Locations]::JoinedDomain $DialogPicker.AllowedObjectTypes = [CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes]::Groups,[CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes]::Users $DialogPicker.MultiSelect = $true $frontwebconfig = ' ' function sitegen($name) { $sitedir = "$basedir$name" $siteweb = "$baseweb$name" $sitepool = "$basepool$name" if (siteexists($name)) { return $false } # Create app pool New-Item $sitepool | out-null # Create website New-Item $siteweb -bindings @{protocol="http";bindingInformation=":80:$name"} -physicalPath $sitedir | out-null Set-ItemProperty $siteweb -name applicationPool -value $name | out-null # Create directory New-Item $sitedir -type directory | out-null # Create share $Shares.Create($sitedir, $name, 0) | out-null return $true } function siteexists($name) { $sitedir = "$basedir$name" $siteweb = "$baseweb$name" $sitepool = "$basepool$name" return (Test-path($sitedir)) -or (Test-path($sitedir)) -or (Test-path($sitepool)) } function siterm($name) { $sitedir = "$basedir$name" $siteweb = "$baseweb$name" $sitepool = "$basepool$name" # Remove directory if (Test-Path $sitedir) { Remove-Item $sitedir -Recurse | out-null } # Remove website if (Test-Path $siteweb) { Remove-Item $siteweb -Recurse | out-null } # Remove app pool if (Test-Path $sitepool) { Remove-Item $sitepool -Recurse | out-null } # Remove share $share = Get-WmiObject -Class Win32_Share -ComputerName . -Filter "Name='$name'" if ($share) { $share.delete() | out-null } } function dbgen($name) { if (dbexists($name)) { return $false } $db = New-Object Microsoft.SqlServer.Management.Smo.Database($sqlserver, $name) $db.Create() | out-null return $true } function dbexists($name) { $db = $sqlserver.Databases[$name] if ($db) { return $true } else { return $false } } function dbrm($name) { if (dbexists($name)) { $sqlserver.KillDatabase($name) | out-null } } function apigen($name) { return (sitegen("api.$name")) -and (dbgen($name)) } function apiexists($name) { return (siteexists("api.$name")) -or (dbexists($name)) } function apirm($name) { siterm("api.$name") dbrm($name) } function frontgen($name) { if (-not (sitegen($name))) { return $false } $webconfig = $frontwebconfig -replace "%%API_HOST%%", "api.$name" $webconfig | Set-Content "$basedir$name\web.config" return $true } function frontexists($name) { return (siteexists($name)) } function frontrm($name) { siterm($name) } function appgen($name) { return (frontgen($name)) -and (apigen($name)) } function appexists($name) { return (frontexists($name)) -or (apiexists($name)) } function apprm($name) { frontrm($name) apirm($name) } function getusers() { $DialogPicker.ShowDialog() return $DialogPicker.SelectedObjects }