Skip to content

Commit

Permalink
Merge pull request #375 from troettinger/vnext
Browse files Browse the repository at this point in the history
Syndication Tool
  • Loading branch information
troettinger authored Nov 22, 2017
2 parents 22810b7 + 4018f96 commit c46d2e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
33 changes: 10 additions & 23 deletions Syndication/AzureStack.MarketplaceSyndication.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,22 @@ function Sync-AzSOfflineMarketplaceItem{
[ValidateNotNullorEmpty()]
[String] $Destination,

[Parameter(Mandatory=$false, ParameterSetName='SyncOfflineAzsMarketplaceItem')]
[Parameter(Mandatory=$true, ParameterSetName='SyncOfflineAzsMarketplaceItem')]
[ValidateNotNullorEmpty()]
[String] $AzureTenantID,

[Parameter(Mandatory=$false, ParameterSetName='SyncOfflineAzsMarketplaceItem')]
[Parameter(Mandatory=$true, ParameterSetName='SyncOfflineAzsMarketplaceItem')]
[ValidateNotNullorEmpty()]
[String] $AzureSubscriptionID

)


If ($tenantid.isPresent)
{
$azureAccount = Add-AzureRmAccount -TenantId $AzureTenantID
}

elseif($AzureSubscriptionID.isPresent)
{
Add-AzureRmAccount -subscriptionid $AzureSubscriptionID
}

else
{
$azureAccount = Add-AzureRmAccount
}


$azureAccount = Add-AzureRmAccount -subscriptionid $AzureSubscriptionID -TenantId $AzureTenantID

$azureEnvironment = Get-AzureRmEnvironment -Name $Cloud

$subscription=Get-AzureRmSubscription
$subscriptionId=$subscription[0].SubscriptionId

$resources=Get-AzureRmResource
$resource=$resources.resourcename
$registrations=$resource|where-object {$_ -like "AzureStack*"}
Expand All @@ -61,7 +45,7 @@ function Sync-AzSOfflineMarketplaceItem{
$token = $tokens |Where Resource -EQ $azureEnvironment.ActiveDirectoryServiceEndpointResourceId |Where DisplayableId -EQ $azureAccount.Context.Account.Id |Sort ExpiresOn |Select -Last 1


$uri1 = "$($azureEnvironment.ResourceManagerUrl.ToString().TrimEnd('/'))/subscriptions/$($subscriptionId.ToString())/resourceGroups/azurestack/providers/Microsoft.AzureStack/registrations/$($Registration.ToString())/products?api-version=2016-01-01"
$uri1 = "$($azureEnvironment.ResourceManagerUrl.ToString().TrimEnd('/'))/subscriptions/$($AzureSubscriptionID.ToString())/resourceGroups/azurestack/providers/Microsoft.AzureStack/registrations/$($Registration.ToString())/products?api-version=2016-01-01"
$Headers = @{ 'authorization'="Bearer $($Token.AccessToken)"}
$products = (Invoke-RestMethod -Method GET -Uri $uri1 -Headers $Headers).value

Expand Down Expand Up @@ -110,15 +94,15 @@ $Marketitems|Out-GridView -Title 'Azure Marketplace Items' -PassThru|foreach{
$productid=$_.id

# get name of azpkg
$uri2 = "$($azureEnvironment.ResourceManagerUrl.ToString().TrimEnd('/'))/subscriptions/$($SubscriptionId.ToString())/resourceGroups/azurestack/providers/Microsoft.AzureStack/registrations/$Registration/products/$($productid)?api-version=2016-01-01"
$uri2 = "$($azureEnvironment.ResourceManagerUrl.ToString().TrimEnd('/'))/subscriptions/$($AzureSubscriptionID.ToString())/resourceGroups/azurestack/providers/Microsoft.AzureStack/registrations/$Registration/products/$($productid)?api-version=2016-01-01"
Write-Debug $URI2
$Headers = @{ 'authorization'="Bearer $($Token.AccessToken)"}
$productDetails = Invoke-RestMethod -Method GET -Uri $uri2 -Headers $Headers
$azpkgName = $productDetails.properties.galleryItemIdentity


# get download location for apzkg
$uri3 = "$($azureEnvironment.ResourceManagerUrl.ToString().TrimEnd('/'))/subscriptions/$($SubscriptionId.ToString())/resourceGroups/azurestack/providers/Microsoft.AzureStack/registrations/$Registration/products/$productid/listDetails?api-version=2016-01-01"
$uri3 = "$($azureEnvironment.ResourceManagerUrl.ToString().TrimEnd('/'))/subscriptions/$($AzureSubscriptionID.ToString())/resourceGroups/azurestack/providers/Microsoft.AzureStack/registrations/$Registration/products/$productid/listDetails?api-version=2016-01-01"
$uri3
$downloadDetails = Invoke-RestMethod -Method POST -Uri $uri3 -Headers $Headers

Expand Down Expand Up @@ -147,12 +131,15 @@ $Marketitems|Out-GridView -Title 'Azure Marketplace Items' -PassThru|foreach{
# download vhd
$vhdName = $productDetails.properties.galleryItemIdentity
$vhdSource = $downloadDetails.properties.osDiskImage.sourceBlobSasUri
If ([string]::IsNullOrEmpty($vhdsource)) {exit} else {
$FileExists=Test-Path "$destination\$productid.vhd"
If ($FileExists -eq $true) {Remove-Item "$destination\$productid.vhd" -force} else {
New-Item "$destination\$productid.vhd" }
$vhdDestination = "$destination\$productid.vhd"

Start-BitsTransfer -source $vhdSource -destination $vhdDestination -Priority High
}
}

else {
$a.popup("Legal Terms not accpeted, canceling")
Expand Down
2 changes: 1 addition & 1 deletion Syndication/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Import-Module .\AzureStack.MarketplaceSyndication.psm1

## Launch the Tool
```powershell
Sync-AzSOfflineMarketplaceItems -destination c:\donwloadfolder
Sync-AzSOfflineMarketplaceItem -destination c:\donwloadfolder
```

## Optional Parameters
Expand Down

0 comments on commit c46d2e2

Please sign in to comment.