简体   繁体   English

Powershell DSC-将MSI文件下载到VM

[英]Powershell DSC - Download MSI file to VM

I've tried the following example to download from Azure blob or Azure file share but never got it to work. 我尝试过以下示例从Azure blob或Azure文件共享下载,但从未成功。 Is there a way to download files to VM passing credentials or keys? 是否可以通过凭据或密钥将文件下载到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
                 }  
    }

I also tried the using File module. 我还尝试了使用文件模块。

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

If you download file from Azure File Share, you could refer to this example . 如果从Azure File Share下载文件,则可以参考此示例 Add following script to your script. 将以下脚本添加到您的脚本中。

Configuration SimpleExampleWithCredentials {

  param(

      [Parameter(Mandatory=$true)]

      [ValidateNotNullOrEmpty()]

      [PSCredential]$Credentials

  )

If you use classic VM, you could use the following cmdlets. 如果您使用经典VM,则可以使用以下cmdlet。

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

If you use ARM VM, you should use cmdlet Set-​Azure​Rm​VM​Dsc​Extension . 如果使用ARM VM,则应使用cmdlet Set-AzureRmVMDscExtension

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM