1

I've been trying to make a DSC Script work using DSC File Resource to copy files from Azure File Storage to local as shown below

 File FabrikamFibreSourceFiles
    {
        Ensure = "Present"  # You can also set Ensure to "Absent"
        Type = "Directory“ # Default is “File”
        Recurse = $true
        Credential = $storageCredential
        SourcePath = "\\sriksstore.file.core.windows.net\fabrikamfibreshare" # This is a path that has web files
        DestinationPath = "C:\inetpub\dev\fabrikamfibre\" # The path where we want to ensure the web files are present
    }

The $storageCredential is passed while invoking as shown below.

$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName  -StorageAccountKey $storageKey
$secpasswd = ConvertTo-SecureString $storageKey -AsPlainText -Force
$storagecreds = New-Object System.Management.Automation.PSCredential ($storageAccountName, $secpasswd)

Get-AzureVM -ServiceName fabrikamfibre -Name fabrikamfibre| `
Set-AzureVMDscExtension -StorageContext $storageContext `
-ConfigurationName "FabrikamFibre" -ConfigurationArgument @{ storageCredential= ($storagecreds) }`
-ConfigurationArchive "fabrikamfibredsc.ps1.zip" | Update-AzureVM

It fails to copy the contents with the following errors

An error occurs when accessing the network share with the specified credential. Please make sure the credential is correct and the network share is accessible. Note that Credential should not be specified with the local path. The related file/directory is: \sriksstore.file.core.windows.net\fabrikamfibreshare. A specified logon session does not exist. It may already have been terminated. An error occurs when accessing the network share with the specified credential. Please make sure the credential is correct and the network share is accessible. Note that Credential should not be specified with the local path. The related file/directory is: \sriksstore.file.core.windows.net\fabrikamfibreshare.

It also fails when I try to invoke using Get-Credential as mentioned in various samples, if anyone tried using DSC File resource with Azure File Storage, please help. I've double checked the credentials they are correct, interesting when I use write-verbose to print $storageCredential.Username they always output blank. I'm definitely missing something here.

4

2 回答 2

0

您能否仔细检查配置中 $storageCredential 的声明并确保它是 PSCredential 类型?

configuration MyConfiguration([PSCredential] $storageCredential...) {
   ...
} 

如果这是正确的,您可以检查您的 VM 收到的 storageCredential 的值吗?它将位于名为的文件中的 JSON 对象中

c:\packages\plugins\Microsoft.powershell.dsc\xxxx\runtimesettings\settings.x

于 2015-08-26T15:15:08.437 回答
0

这是一个相当古老的问题,但不幸的是,当使用文件资源从 Azure 文件共享复制文件时,问题仍然存在。我尝试以与问题作者通过 DSC 扩展完全相同的方式使用它并得到相同的错误。我验证了设置文件中的所有凭据都是正确的。事实上,我使用文件资源管理器从 VM 连接到文件共享没有问题。

我最终放弃了使用文件资源并使用脚本资源代替我手动挂载到与 Powershell 的文件共享,将文件复制到本地文件系统,并断开挂载。我将一些变量传递给脚本,例如文件共享凭据、要挂载到的驱动器的字母以及用于删除文件的本地文件路径。在 TestScript 部分,您可以运行任何适合您的验证,例如,使用 Test-Path 来确保文件被复制。希望这可以帮助偶然发现这个问题的人......

    Script CopyFilesFromAzureFileshare
    {
        SetScript =
        {
             New-PSDrive -Name $using:localMountDrive -PSProvider FileSystem -Root $using:fileshareSrcPath -Credential $using:fileshareCredential -Persist

             $src = $using:localMountDrive + ":\*";

             if (-Not (Test-Path $using:localSrcPath))
             {
                  md -path $using:localSrcPath
             }

             Copy-Item $src -Destination $using:localSrcPath -Recurse -Force

             Remove-PSDrive -Name $using:localMountDrive -PSProvider FileSystem 
        }
        TestScript = 
        {
            Test-Path "$using:localSrcPath\$using:fileshareInstallArchive" -PathType Leaf

        }
        GetScript = { @{ Result = '' } }
    }
于 2018-08-04T00:12:28.620 回答