如何使用来自门户网站的PowerShell导出AzureVM配置

时间:2015-08-19 13:48:09

标签: azure azure-powershell

我正在尝试恢复需要在删除VM之前导出VM配置的VM(http://blogs.technet.com/b/keithmayer/archive/2014/02/04/step-by-step-perform-cloud-restores-of-windows-azure-virtual-machines-using-powershell-part-2.aspx)。现在,我试图通过Runbook实现所有这一切。 Export-AzureVM使用该计算机上的Windows PowerShell将配置详细信息保存在本地计算机的文件中。现在,因为我在Azure门户中运行它,有没有办法在Azure Powershell中保存配置文件?

修改 这在Azure门户网站中按预期工作,但从C:驱动器的位置我不确定。

$exportedFile = "C:\file.xml"
New-Item -Path $exportFolder -ItemType Directory
$exportPath = $exportFolder + "\" + $vm.Name + ".xml"
$vm | Export-AzureVM -Path $exportPath

输出:

Directory: C:\
Mode            LastWriteTime        Length      Name             PSComputerName                       
----            ---------            ------      ----             ----------                       
d----           8/20/2015   2:15 PM             ExportVMs         localhost                            

1 个答案:

答案 0 :(得分:3)

您必须将导出的文件复制到可以从任何地方访问的某个位置。当然,您可以从Internet中存在的所有文件存储服务中进行选择。我的第一种方法是将这些导出的文件复制到Azure存储帐户。

以下是一些示例PowerShell代码,其中显示了如何将文件复制到Azure存储帐户。该示例甚至创建了一个新的存储帐户。如果您已经拥有要使用的Azure存储帐户,只需删除创建新帐户的行。

# Used settings
$subscriptionName = "Your Subscription Name" # Get-AzureSubscription
$location = "West Europe" # Get-AzureLocation
$storageAccountName = "mystorageaccount123"

# Create storage account and set is as current.
New-AzureStorageAccount -Location $location -StorageAccountName $storageAccountName -Type Standard_LRS
Set-AzureSubscription -SubscriptionName $subscriptionName -CurrentStorageAccountName $storageAccountName

$container = "exportedfiles"

# Create destination container in storage if it does not exist.
$containerList = Get-AzureStorageContainer -Name $container -ErrorAction Ignore # Ignore error if container not found.
if ($containerList.Length -eq 0) {
    New-AzureStorageContainer -Name $container -Permission Off
}

$exportedFile = "C:\file.xml" # That is something you should know where you have exported your file.

# Upload PowerShell file
Set-AzureStorageBlobContent -Container $container -File $exportedFile -Force

我从GitHub Gist上的示例代码中获取了示例代码,并根据您的问题进行了调整。如果您愿意,可以找到整个sample here

如果您需要一个工具来访问Azure存储帐户,see this list。有一些很好的工具。我个人使用ClumsyLeaf CloudXplorer。