Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xWebVirtualDirectory setting PhysicalPath to UNC #94

Closed
zaceverett opened this issue Feb 25, 2016 · 3 comments · Fixed by #634
Closed

xWebVirtualDirectory setting PhysicalPath to UNC #94

zaceverett opened this issue Feb 25, 2016 · 3 comments · Fixed by #634
Labels
enhancement The issue is an enhancement request.

Comments

@zaceverett
Copy link

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

@kwirkykat kwirkykat added enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community. labels Aug 19, 2016
@remcoeissing
Copy link
Contributor

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?

@rosberglinhares
Copy link
Contributor

rosberglinhares commented Jul 12, 2017

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'
    }
}

@johlju
Copy link
Member

johlju commented Apr 25, 2018

@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 pushed a commit that referenced this issue Jul 7, 2024
- WebVirtualDirectory
  - Added Credential paramater
  - Fixed error when using UNC PhysicalPath (issue #94).
@johlju johlju removed the help wanted The issue is up for grabs for anyone in the community. label Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is an enhancement request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants