4

我创建了一个运行手册来“将文件从 Azure 存储复制到 AzureVM”。在测试时,我收到以下异常,指出“找不到‘Connect-Azure’命令”。另一端的任何人都可以,请调查一下并帮助我。

这是屏幕截图:

在此处输入图像描述

代码:

workflow Copy-FileFromAzureStorageToAzureVM {
param
(
    [parameter(Mandatory=$true)]
    [String]
    $AzureConnectionName,

    [parameter(Mandatory=$true)]
    [String]
    $CredentialAssetNameWithAccessToVM,

    [parameter(Mandatory=$true)]
    [String]
    $StorageAccountName,

    [parameter(Mandatory=$true)]
    [String]
    $ContainerName,

    [parameter(Mandatory=$true)]
    [String]
    $BlobName,

    [parameter(Mandatory=$true)]
    [String]
    $PathToPlaceFile,

    [parameter(Mandatory=$true)]
    [object]
    $VM
)

$TempFileLocation = "C:\$BlobName"

Connect-Azure -AzureConnectionName $AzureConnectionName

Write-Verbose "Downloading $BlobName from Azure Blob Storage to $TempFileLocation"

InlineScript {
    Select-AzureSubscription -SubscriptionName $Using:AzureConnectionName

    $StorageAccount = (Get-AzureStorageAccount -StorageAccountName $Using:StorageAccountName).Label

    Set-AzureSubscription `
        -SubscriptionName $Using:AzureConnectionName `
        -CurrentStorageAccount $StorageAccount

    $blob = 
        Get-AzureStorageBlobContent `
            -Blob $Using:BlobName `
            -Container $Using:ContainerName `
            -Destination $Using:TempFileLocation `
            -Force
}

Write-Verbose ("Copying $BlobName to $PathToPlaceFile on " + $VM.Name)

Copy-ItemToAzureVM `
    -AzureConnectionName $AzureConnectionName `
    -ServiceName $VM.ServiceName `
    -VMName $VM.Name `
    -VMCredentialName $CredentialAssetNameWithAccessToVM `
    -LocalPath $TempFileLocation `
    -RemotePath $PathToPlaceFile }
4

1 回答 1

3

这是“将文件从 Azure 存储复制到 AzureVM”的自定义运行手册

workflow Copy-ItemToAzureVM { 
param 
( 
    [parameter(Mandatory=$true)] 
    [String] 
    $AzureSubscriptionName, 

    [parameter(Mandatory=$true)] 
    [PSCredential] 
    $AzureOrgIdCredential, 

            [parameter(Mandatory=$True)]
    [String]
    $StorageAccountName,

    [parameter(Mandatory=$True)]
    [String]
    $ContainerName,

    [parameter(Mandatory=$True)]
    [String]
    $BlobName,

    [parameter(Mandatory=$true)] 
    [String] 
    $ServiceName, 

    [parameter(Mandatory=$true)] 
    [String] 
    $VMName,   

    [parameter(Mandatory=$true)] 
    [String] 
    $VMCredentialName, 

    [parameter(Mandatory=$true)] 
    [String] 
    $LocalPath, 

    [parameter(Mandatory=$true)] 
    [String] 
    $RemotePath,  

    [parameter(Mandatory=$False)]
    [String]
    $PathToPlaceBlob = "C:\"        
) 
$Null = Add-AzureAccount -Credential $AzureOrgIdCredential 
$Null = Select-AzureSubscription -SubscriptionName $AzureSubscriptionName

Write-Verbose "Downloading $BlobName from Azure Blob Storage to $PathToPlaceBlob"

Set-AzureSubscription `
    -SubscriptionName $AzureSubscriptionName `
    -CurrentStorageAccount $StorageAccountName

$blob = 
    Get-AzureStorageBlobContent `
        -Blob $BlobName `
        -Container $ContainerName `
        -Destination $PathToPlaceBlob `
        -Force
try {
    Get-Item -Path "$PathToPlaceBlob\$BlobName" -ErrorAction Stop
}
catch {
    Get-Item -Path $PathToPlaceBlob
}
$Credential = Get-AutomationPSCredential -Name $VMCredentialName     
if ($Credential -eq $null) 
{ 
    throw "Could not retrieve '$VMCredentialName' credential asset. Check that you created this asset in the Automation service." 
}      
$Uri = Connect-AzureVM -AzureSubscriptionName $AzureSubscriptionName -AzureOrgIdCredential $AzureOrgIdCredential –ServiceName $ServiceName –VMName $VMName 
InlineScript { 
    $ConfigurationName = "HighDataLimits"  
    Invoke-Command -ScriptBlock { 
        $ConfigurationName = $args[0] 
        $Session = Get-PSSessionConfiguration -Name $ConfigurationName 

        if(!$Session) { 
            Write-Verbose "Large data sending is not allowed. Creating PSSessionConfiguration $ConfigurationName" 

            Register-PSSessionConfiguration -Name $ConfigurationName -MaximumReceivedDataSizePerCommandMB 500 -MaximumReceivedObjectSizeMB 500 -Force | Out-Null 
        } 
    } -ArgumentList $ConfigurationName -ConnectionUri $Using:Uri -Credential $Using:Credential -ErrorAction SilentlyContinue      
    $Content = Get-Content –Path $Using:LocalPath –Encoding Byte 

    Write-Verbose ("Retrieved local content from $Using:LocalPath") 

    Invoke-Command -ScriptBlock { 
        param($Content, $RemotePath) 

        $Content | Set-Content –Path $RemotePath -Encoding Byte 
    } -ArgumentList $Content, $Using:RemotePath -ConnectionUri $Using:Uri -Credential $Using:Credential -ConfigurationName $ConfigurationName 

    Write-Verbose ("Wrote content from $Using:LocalPath to $Using:VMName at $Using:RemotePath") 
} }
于 2016-03-16T15:35:34.807 回答