-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathImport-VmSetting.ps1
42 lines (33 loc) · 1.5 KB
/
Import-VmSetting.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
param
(
[ValidateNotNullOrEmpty()]
[Parameter(Mandatory=$true, HelpMessage="The storage key for the storage account where custom images are stored")]
[string] $StorageAccountName,
[ValidateNotNullOrEmpty()]
[Parameter(Mandatory=$true, HelpMessage="The storage key for the storage account where custom images are stored")]
[string] $StorageContainerName,
[ValidateNotNullOrEmpty()]
[Parameter(Mandatory=$true, HelpMessage="The storage key for the storage account where custom images are stored")]
[string] $StorageAccountKey
)
$ErrorActionPreference = 'Stop'
. "./Utils.ps1"
$SourceStorageContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$jsonBlobs = Get-AzureStorageBlob -Context $SourceStorageContext -Container $StorageContainerName -Blob '*json'
Write-Host "Downloading $($jsonBlobs.Count) json files from storage account"
$downloadFolder = Join-Path $env:TEMP 'CustomImageDownloads'
if(Test-Path -Path $downloadFolder)
{
Remove-Item $downloadFolder -Recurse | Out-Null
}
New-Item -Path $downloadFolder -ItemType Directory | Out-Null
$sourceImageInfos = @()
$jsonBlobs | Get-AzureStorageBlobContent -Destination $downloadFolder | Out-Null
$downloadedFileNames = Get-ChildItem -Path $downloadFolder
foreach($file in $downloadedFileNames)
{
$imageObj = (gc $file.FullName -Raw) | ConvertFrom-Json
$imageObj.timestamp = [DateTime]::Parse($imageObj.timestamp)
$sourceImageInfos += $imageObj
}
$sourceImageInfos