none
DSC resource to copy files from Azure file storage

    Question

  • Hi 

    We have uploaded few exe to azure file storage . We want to download these exe in an azure vm and set up the azure VM like installing SQL server etc. Is there any DSC resource which will copy file from Azure storage and make is available in azure VM

    Thanks



    Girish

    Wednesday, May 3, 2017 6:21 PM

All replies

  • DSC File resource should help

    https://blogs.msdn.microsoft.com/brian_farnhill/2015/03/15/using-dsc-to-download-from-azure-file-storage-to-an-azure-vm/

    https://msdn.microsoft.com/en-us/powershell/dsc/fileresource


    cheers..uc

    Thursday, May 4, 2017 7:48 AM
  • The DSC File Resource will let you grab a package from a URL:

    File DownloadPackage        {            	
    Ensure = "Present"              	
    Type = "File"             	
    SourcePath ="https://storageaccount.blob.core.windows.net/mycontainer/file.zip"            	
    DestinationPath = "C:\packages"            
    }


    If the packages you are downloading are sensitive then you want to make sure you protect your storage account with a SAS key and use that in your download.


    Sam Cogan Microsoft Azure MVP
    Blog | Twitter

    • Proposed as answer by meera12 Tuesday, September 4, 2018 6:10 AM
    Thursday, May 4, 2017 9:18 AM
  • Hi

    We are using the "File" DSC resource as shown below 

    File SQLBinaryDownload
             {
                 DestinationPath = "C:\SQLInstall"
                 Credential = $Storagecredential
                 Ensure = "Present"
                 SourcePath = "\\*****.file.core.windows.net\dscexe\sqlengine\setup.exe"
                 Type = "File"
                 Recurse = $true
                 Force =  $true
             }

    We use the azure file storage but getting an error as below 

    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.

    We are able to login to Azure file share from Azure VM using the credentials but when done using DSC resource getting the above error

    Thanks


    Girish


    Friday, May 5, 2017 1:48 PM
  • Hi 

    There is also a similar issue mentioned in this link 

    http://stackoverflow.com/questions/36038452/azure-automation-powershell-dsc-copy-files-off-unc-share

    Thanks


    Girish

    Friday, May 5, 2017 1:54 PM
  • Since this issue is related to Azure Automation I suggest you post your query here so it reaches the right audience.
    Tuesday, May 9, 2017 5:23 AM
  • I don't believe this is related to Azure Automation. PowerShell DSC can be used without automation. The issue that is being experienced is the inability for Azure Files Shares to be accessed from a DSC resource, so I would say the storage forum is the right place.

    Sam Cogan Microsoft Azure MVP
    Blog | Twitter

    Tuesday, May 9, 2017 8:21 AM
  • to me, problem appears in the way credential need to be specified. I did some test and I was able to get the file copied using dsc File resource. Here is what I did (same is for Azure Resource Manager VM).

    Sample DSC configuration that was used to test (ensure that you update sourcepath with your storage account and file/share details if you intend to use this sample). For the reference, this file was saved to c:\temp\dscFileCopyConf.ps1:

    Configuration AzureStorageFileCopyToVMWithCreds
    {
        param( 
          [Parameter(Mandatory=$true)] 
          [ValidateNotNullorEmpty()] 
          [PSCredential]
          $storageCredential
        )
    
        Node "localhost"
        {
            File FileCopy
            {
                Ensure = "Present"  # You can also set Ensure to "Absent"
                Type = "File" # Default is "File".
                Recurse = $false # Ensure presence of subdirectories, too
                SourcePath = "\\yourstorageaccount.file.core.windows.net\yourfileshare\yourfile.zip"
                DestinationPath = "C:\Users\Public\Documents\DSCDemo\yourfile.zip"
                Credential = $storageCredential
            }
    
            Log AfterDirectoryCopy
            {
                # The message below gets written to the Microsoft-Windows-Desired State Configuration/Analytic log
                Message = "Finished running the file resource with ID FileCopy"
                DependsOn = "[File]FileCopy" # This means run "FileCopy" first.
            }
        }
    }

    Next, these two commands were run to publish the DSC configuration and apply it to a VM named "yourvmname" (remember to replace it with your actual vm name).

    The ConfigurationArgument parameter is used to pass defined parameters to DSC configuration. Here, username will be your storage account name and password will be your storage account key.

    $dscConf = Publish-AzureRmVMDscConfiguration -ConfigurationPath c:\temp\dscFileCopyConf.ps1 -ResourceGroupName your-resource-group -StorageAccountName yourstorageaccount -Force
    
    $dscExtStatus = Set-AzureRmVMDscExtension -ResourceGroupName your-resource-group -VMName yourvmname -ArchiveStorageAccountName yourstorageaccount  -ArchiveBlobName dscFileCopyConf.ps1.zip -ConfigurationName "AzureStorageFileCopyToVMWithCreds"  -ConfigurationArgument @{storageCredential = (Get-Credential) }
    
    

    ensure to replace parameter values appropriately if you are using the sample.

    I referenced this document for PowerShell cmdlets that are used above.

    https://docs.microsoft.com/en-us/azure/virtual-machines/windows/extensions-dsc-overview


    cheers..uc

    • Proposed as answer by Md Shihab Thursday, June 1, 2017 10:12 AM
    Monday, May 15, 2017 3:32 PM
  • the sample configuration was taken from this link

    https://msdn.microsoft.com/en-us/powershell/dsc/fileresource


    cheers..uc

    Monday, May 15, 2017 3:33 PM
  • I agree.. this is not directly related to Azure Automation.

    cheers..uc

    Monday, May 15, 2017 3:35 PM
  • And HOW do I apply the SAS token for the download?
    Monday, October 2, 2017 9:12 AM
  • You can start off by referring to this document that explains the details about SAS.

    -----------------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.

    Wednesday, October 11, 2017 9:07 AM
  • Relative path is not supported. Error is thrown if the same is used in DSC. Please suggest.
    Tuesday, September 4, 2018 6:10 AM
  • File DownloadPackage        {             Ensure = "Present"               Type = "File"              SourcePath ="https://storageaccount.blob.core.windows.net/mycontainer/file.zip"             DestinationPath = "C:\packages"             }

    Relative path is not supported. Error is thrown if the same is used in DSC. Please suggest.

    Archive DownloadPackage    
    {           
    Ensure = "Present"             
        Path = $WebDeployPackagePath
        Destination = "c:\Test" 
    }

    Throws Path not found error . But when the path is browsed it downloads the file

    Tuesday, September 4, 2018 6:39 AM
  • Import “xPSDesiredStateConfiguration” Modules, it is a part of the Windows PowerShell Desired State Configuration (DSC) Resource Kit, This module contains the xDscWebService, xWindowsProcess, xService, xPackage, xArchive, xRemoteFile, xPSEndpoint and xWindowsOptionalFeature resources.

    You may refer the suggestions outlined in the SO thread which addresses similar issue.


    -----------------------------------------------------------------------------------------------

    If this answer was helpful, click “Mark as Answer” or “Up-Vote”. To provide additional feedback on your forum experience, click here

    Thursday, September 13, 2018 10:19 AM
    Moderator
  • Checking in to see if the above response helped to answer your query. Let us know if there are still any additional issues we can help with.
    Tuesday, September 18, 2018 5:26 AM
    Moderator