I've written the following script to add websites stored in a directory structure that is as follows
d:\Websites\google.com\Site\
where \Site is the virtual root of the website.
Whenever I run the script, I get
New-Item : Index was outside the bounds of the array
And I don't remember how to get the stack trace to paste here but when I did it yesterday, it was a problem in the method GenerateSiteID or something similarly named.
$websiteDirs = Get-ChildItem -Path "d:\Websites"
foreach( $dir in $websiteDirs ) {
$webRoot = join-path $dir.FullName Site
New-Website -name $dir.Name -physicalPath $webRoot -HostHeader $dir.Name
}