WebAdministrationDsc icon indicating copy to clipboard operation
WebAdministrationDsc copied to clipboard

xWebVirtualDirectory setting PhysicalPath to UNC

Open zaceverett opened this issue 9 years ago • 3 comments

Setting a PhysicalPath to UNC for a VirtualDirectory fails.

Perhaps we need to change

New-WebVirtualDirectory -Site $Website -Application $WebApplication -Name $Name -PhysicalPath $PhysicalPath

for

$virtualDirectory = Get-WebVirtualDirectoryInternal -Site $Website -Name $Name -Application $WebApplication

$virtualDirectoryPath = "IIS:\Sites$Website$Name"

New-Item $virtualDirectoryPath -Type VirtualDirectory -PhysicalPath $PhysicalPath

zaceverett avatar Feb 25 '16 17:02 zaceverett

I ran a few tests using a UNC directory for the virtual directory and this all works fine for me. For example the bellow example resulted in a virtual directory being created and serving files from the UNC directory.

Website = "Default Web Site"
WebApplication = ''
PhysicalPath = "\\IIS02\remote_vdir"
Name = 'UNCExample'
Ensure = 'Present'

Could you share what you used?

remcoeissing avatar Dec 17 '16 11:12 remcoeissing

In my case, the error occurs with the following configuration:

Configuration ConfigurationTest
{
    Import-DscResource -Module xWebAdministration
    
    xWebsite DefaultWebSite
    {
        Ensure = 'Present'
        Name   = 'Default Web Site'
        State  = 'Started'
    }

    Log LogUserName
    {
        Message = "USERNAME = $env:USERNAME"
    }

    Script ScriptUserName
    {
        TestScript =
        {
            Write-Verbose "USERNAME = $env:USERNAME"
            return $true
        }
        SetScript = { }
        GetScript = { @{} }          
    }

    xWebVirtualDirectory NewVirtualDir
    {
        Name = 'VirtualDirTest'
        Website = 'Default Web Site'
        WebApplication = ''
        PhysicalPath = '\\winserver2012r2disks576.file.core.windows.net\filesharetest'
        Ensure = 'Present'
        DependsOn = '[xWebsite]DefaultWebSite'
    }
}

If I am logged as rosberg and my computer name is WinServer2016, the result is:

[[Log]LogUserName] USERNAME = rosberg
[[Script]ScriptUserName] USERNAME = WinServer2016$
Parameter 'PhysicalPath' should point to existing path.
    + CategoryInfo          : NotSpecified: (:) [], CimException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.IIs.PowerShell.Provider.NewVirtualDirectoryCommand
    + PSComputerName        : localhost

The log for the resource [Script]ScriptUserName shows that DSC runs under the LocalSystem account. So, the error is probably because you do not have the drive mapped for this user. One solution then is connect to your UNC path before using the xWebVirtualDirectory resource:

Configuration ConfigurationTest
{
    Import-DscResource –ModuleName PSDesiredStateConfiguration
    Import-DscResource -ModuleName xWebAdministration
    
    xWebsite DefaultWebSite
    {
        Ensure = 'Present'
        Name   = 'Default Web Site'
        State  = 'Started'
    }

    Script MapDrive
    {
        TestScript =
        {
            Test-Path W:
        }
        SetScript =
        {
            $acctKey = ConvertTo-SecureString -String "<key>" -AsPlainText -Force
            $credential = New-Object System.Management.Automation.PSCredential -ArgumentList "Azure\winserver2012r2disks576", $acctKey
            New-PSDrive -Name W -PSProvider FileSystem -Root "\\winserver2012r2disks576.file.core.windows.net\filesharetest" -Credential $credential
        }
        GetScript = { @{} }
    }

    xWebVirtualDirectory NewVirtualDir
    {
        Ensure         = 'Present'
        Name           = 'VirtualDirTest'
        Website        = 'Default Web Site'
        WebApplication = ''
        PhysicalPath   = '\\winserver2012r2disks576.file.core.windows.net\filesharetest'
        DependsOn      = '[xWebsite]DefaultWebSite', '[Script]MapDrive'
    }
}

rosberglinhares avatar Jul 12 '17 22:07 rosberglinhares

@rosberglinhares Maybe the resource should have an option to connect to the UNC path prior setting up the virtual directory? Maybe there could be an credential parameter that triggers this New-PSDrive? But will the virtual directory reconnect automatically once created if the PSDrive ould be disconnected?

johlju avatar Apr 25 '18 16:04 johlju