【问题标题】:Cannot find the 'Connect-Azure' command找不到“连接 Azure”命令
【发布时间】:2016-03-18 19:49:52
【问题描述】:

我创建了“将文件从 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 }

【问题讨论】:

  • 我不熟悉Connect-Azure 命令,你从哪里得到的?如果您使用的是在您的自动化帐户中定义的连接,您应该执行类似$AzureConn = Get-AutomationConnection -Name $AzureConnectionName 的操作
  • 我们从库中定义了一个名为“Connect-Azure”的运行手册。我正在尝试导入那个。但是当我试图测试它说“运行手册已被贬低”时。
  • 并引发异常,提示“异常无法检索 'Visual Studio Enterprise with MSDN' 连接资产。请检查您是否首先在自动化服务中创建了它。”
  • Connect-Azure Runbook 已弃用。它仍然有效,但已被弃用。就您遇到的异常而言,这是因为您没有创建名为“Visual Studio Enterprise with MSDN”的连接资产。请参阅blogs.technet.com/b/orchestrator/archive/2014/04/11/…,了解如何设置 Azure 自动化以使用基于证书的身份验证与 Azure 对话。
  • 我已经尝试过“Connect-Azure”运行手册,它有效,但我收到警告说该运行手册已被弃用。即便如此,我已经发布了它,在上面的代码中导入没有问题。

标签: azure azure-automation


【解决方案1】:

这是“将文件从 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") 
} }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-27
    • 2022-08-02
    • 2012-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多