Skip to content

Instantly share code, notes, and snippets.

@rheid
Last active February 23, 2016 20:28
Show Gist options
  • Save rheid/6c671eab99ba0e1c4b14 to your computer and use it in GitHub Desktop.
Save rheid/6c671eab99ba0e1c4b14 to your computer and use it in GitHub Desktop.
Create IIS WebSite from Folder-Struktur
$Path = "C:\inetpub\wwwroot\static"
$Folders = Get-ChildItem $Path -attributes D
$loop = 0
foreach ($folder in $Folders)
{
#Get Folder-Informationen form Filessystem
$loop = $loop + 1;
$sitefilepath = $folder.Fullname
$sitehostname = $folder.name
#Check Replacement with www
$a = $sitehostname
[regex]$regex = '\.'
$count = $regex.matches($a).count
If ($count -gt 1) {
$sitehostname = $folder.name
Write-Host "Create now IIS-Website with Host:" $sitehostname -ForegroundColor Green
New-WebSite -Name $sitehostname -Port 80 -HostHeader $sitehostname -PhysicalPath $sitefilepath
}
$sitehostname = "www." + $folder.name
Write-Host "Create now IIS-Website with Host:" $sitehostname -ForegroundColor Green
New-WebSite -Name $sitehostname -Port 80 -HostHeader $sitehostname -PhysicalPath $sitefilepath
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment