Hi,
Using Windows 7 x64. I would like to create a Virtual Directory which is mapped to a UNC network share . The code below failed. Can you please help me to fix it? And possibly also how to set the user credentials to access the UNC folder?
Thanks very much for any help.
$webAdminModule = get-module -ListAvailable | ? { $_.Name -eq "webadministration" }
If ($webAdminModule -ne $null) {
Write-Host -foregroundcolor DarkCyan "Importing IIS7 Module WebAdministration"
Import-Module WebAdministration
}
$cfgSiteName = "My Web Site"
$cfgDocVirtualFolder = "CommonDocs"
$cfgDocPhysicalFolder = "\\MYFILESERVER\MySharedPDF"
if (-not (Test-Path -path IIS:\Sites\$cfgSiteName\$cfgDocVirtualFolder)) {
Write-Host -foregroundcolor DarkGreen "Create Virtual Folder: " -NoNewLine;
Write-Host -foregroundcolor Green $cfgSiteName\$cfgDocVirtualFolder;
New-Item 'IIS:\Sites\$cfgSiteName\$cfgDocVirtualFolder' -PhysicalPath $cfgDocPhysicalFolder -Type VirtualDirectory
}
The error message is:
New-Item : Parent node has no children of type VirtualDirectory.
Parameter name: path
At C:\Test\CreateVirtualFolder.ps1:51 char:10
+ New-Item <<<< 'IIS:\Sites\$cfgSiteName\$cfgDocVirtualFolder' -type VirtualDirectory -physicalPath $cfgDocPhysicalFolder
+ CategoryInfo : InvalidArgument: (:) [New-Item], ArgumentException
+ FullyQualifiedErrorId : Parent node has no children of type VirtualDirectory.
Parameter name: path,Microsoft.PowerShell.Commands.NewItemCommand