From a3c484d22929d751e7993b6915688cc6c911c1dc Mon Sep 17 00:00:00 2001 From: troettinger Date: Tue, 21 Nov 2017 00:01:18 +0100 Subject: [PATCH 1/4] Token change for 1.2.11 --- Syndication/AzureStack.MarketplaceSyndication.psm1 | 2 +- Syndication/readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Syndication/AzureStack.MarketplaceSyndication.psm1 b/Syndication/AzureStack.MarketplaceSyndication.psm1 index 1818f848..12597c8a 100644 --- a/Syndication/AzureStack.MarketplaceSyndication.psm1 +++ b/Syndication/AzureStack.MarketplaceSyndication.psm1 @@ -57,7 +57,7 @@ function Sync-AzSOfflineMarketplaceItem{ $registration = $registrations[0] # Retrieve the access token - $tokens = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.TokenCache.ReadItems() + $tokens = [Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache]::DefaultShared.ReadItems() $token = $tokens |Where Resource -EQ $azureEnvironment.ActiveDirectoryServiceEndpointResourceId |Where DisplayableId -EQ $azureAccount.Context.Account.Id |Sort ExpiresOn |Select -Last 1 diff --git a/Syndication/readme.md b/Syndication/readme.md index 8aa01593..5594e0b7 100644 --- a/Syndication/readme.md +++ b/Syndication/readme.md @@ -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 From 7762ab0841853f484b25773283c38a316c6c61dc Mon Sep 17 00:00:00 2001 From: troettinger Date: Tue, 21 Nov 2017 01:24:15 +0100 Subject: [PATCH 2/4] Revert Token change --- Syndication/AzureStack.MarketplaceSyndication.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Syndication/AzureStack.MarketplaceSyndication.psm1 b/Syndication/AzureStack.MarketplaceSyndication.psm1 index 12597c8a..1818f848 100644 --- a/Syndication/AzureStack.MarketplaceSyndication.psm1 +++ b/Syndication/AzureStack.MarketplaceSyndication.psm1 @@ -57,7 +57,7 @@ function Sync-AzSOfflineMarketplaceItem{ $registration = $registrations[0] # Retrieve the access token - $tokens = [Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache]::DefaultShared.ReadItems() + $tokens = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.TokenCache.ReadItems() $token = $tokens |Where Resource -EQ $azureEnvironment.ActiveDirectoryServiceEndpointResourceId |Where DisplayableId -EQ $azureAccount.Context.Account.Id |Sort ExpiresOn |Select -Last 1 From 529913069cc00fa313b6c385b34a5bc50b5a7477 Mon Sep 17 00:00:00 2001 From: troettinger Date: Tue, 21 Nov 2017 20:29:03 +0100 Subject: [PATCH 3/4] Fix for extensions --- Syndication/AzureStack.MarketplaceSyndication.psm1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Syndication/AzureStack.MarketplaceSyndication.psm1 b/Syndication/AzureStack.MarketplaceSyndication.psm1 index 1818f848..79775b48 100644 --- a/Syndication/AzureStack.MarketplaceSyndication.psm1 +++ b/Syndication/AzureStack.MarketplaceSyndication.psm1 @@ -147,12 +147,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") From 4018f961610cf0de5fc359ad785878b502b0af1a Mon Sep 17 00:00:00 2001 From: troettinger Date: Wed, 22 Nov 2017 00:00:16 +0100 Subject: [PATCH 4/4] Make Parameters mandatory --- .../AzureStack.MarketplaceSyndication.psm1 | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/Syndication/AzureStack.MarketplaceSyndication.psm1 b/Syndication/AzureStack.MarketplaceSyndication.psm1 index 79775b48..74cb5288 100644 --- a/Syndication/AzureStack.MarketplaceSyndication.psm1 +++ b/Syndication/AzureStack.MarketplaceSyndication.psm1 @@ -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*"} @@ -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 @@ -110,7 +94,7 @@ $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 @@ -118,7 +102,7 @@ $Marketitems|Out-GridView -Title 'Azure Marketplace Items' -PassThru|foreach{ # 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