2017-05-18 51 views
0

我试过下面的例子从Azure blob或Azure文件共享下载,但从来没有得到它的工作。有没有办法将文件下载到VM传递证书或密钥?Powershell DSC - 下载MSI文件到VM

 Import-DSCResource -ModuleName PSDesiredStateConfiguration, xPSDesiredStateConfiguration   

Node webServer 
{   xRemoteFile Installs 
       { 
       DestinationPath = "C:\Scripts" 
       Credential = $StorageCredential 
       Ensure = "Present" 
       SourcePath = "https://storagename.blob.core.windows.net/installs" 
       Type = "Directory" 
       Recurse = $true 
       } 
    } 

我也尝试过使用File模块。

Import-DSCResource -ModuleName PSDesiredStateConfiguration, xPSDesiredStateConfiguration 

       Node webServer 
       { 
           File Installs 
           { 
           DestinationPath = "C:\Scripts" 
           Credential = $StorageCredential 
           Ensure = "Present" 
           SourcePath = "\\storagename.file.core.windows.net\installs" 
           Type = "Directory" 
           Recurse = $true 
           } 
       } 

回答

1

如果您从Azure File Share下载文件,可以参考此example。将以下脚本添加到脚本中。

Configuration SimpleExampleWithCredentials { 

    param(

     [Parameter(Mandatory=$true)] 

     [ValidateNotNullOrEmpty()] 

     [PSCredential]$Credentials 

) 

如果您使用传统VM,则可以使用以下cmdlet。

Set-AzureVMDscExtension -VM $vm -ConfigurationArchive MyConfiguration.ps1.zip -ConfigurationName MyConfiguration -ConfigurationArgument @{ storageCredential= (Get-Credential) } 

如果使用ARM VM,则应该使用cmdlet Set-​Azure​Rm​VM​Dsc​Extension

+0

我正在使用ARM VM,能否提供使用Set-Azure Rm VM Dsc扩展的示例? – DXH

+0

嗨,你试试这个'设置AzureRmVMDscExtension -Version 2.21 -ResourceGroupName $资源组-VMName $ VMNAME -ArchiveBlobName “Sample.ps1.zip” -ArchiveStorageAccountName “STG” -ConfigurationName MyConfiguration -ConfigurationArgument @ {storageCredential =(GET-凭据) }'? –

+0

此外,我建议你可以使用自定义脚本扩展将文件下载到你的虚拟机,然后使用DSC来安装它们。 –