I am trying to create a / VirtualDirectory web application under a specific subfolder of the IIS 6 website using Powershell as shown below:
IIS website structure <lt; β> Structure of the physical directory
Test (website) ----------------> c:\InetPub SubDirectory ------------------> ..\Subdirectory gadgets (Web App) -----------------> ..\Gadgets
Script
$WebSiteName = "Test" $virtualDirName = "subdirectory\gadgets" $appPoolName = "DefaultAppPool" $VirtalDirHomePath = "c:\InetPub\Subdirectory\Gadgets" $iisWebSite = Get-WmiObject "IISWebServerSetting" ` -Namespace "root\MicrosoftIISv2" ` -filter "ServerComment like '%$WebSiteName%'" $virtualDirSettings = [wmiclass] "root\MicrosoftIISv2:IIsWebVirtualDirSetting" $newVDir = $virtualDirSettings.CreateInstance() $newVDir.Name = ($iisWebSite.Name + '/ROOT/' + $virtualDirName) $newVDir.Path = $VirtalDirHomePath $newVDir.Put(); $nvdir = $iisWebSite.Name + '/ROOT/' + $virtualDirName $nvdir = $nvdir.Replace("\", "/") $v = Get-WmiObject -Class IIsWebVirtualDir -Namespace root\microsoftiisv2 ` -filter "Name='$nvdir'" #Create WebAppliction $v.AppCreate3(2, $appPoolName, 1)
If I specify a $virtualDirName with a forward slash path separator ( subdirectory/gadgets ), calling $newVDir.Put() raises the following exception
Aborting the "Put" call with "0" argument (s): "Win32: the system cannot find the path specified.
If I change $virtualDirName using the backslash path separator (subdirectory \ gadgets), the call to $newVDir.Put() returns successfully.
I am not sure if this is correct.
Is there a better way to create a web application / VirtualDirectory under a specific subfolder and how can I list the VirtualDirectory / WebApplication created under a subfolder.
source share