Created
November 16, 2014 20:01
-
-
Save davideicardi/79ea199ab5550d444a65 to your computer and use it in GitHub Desktop.
Get an azure website publising xml file using PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-AzureWebSitePublishXml | |
{ | |
Param( | |
[Parameter(Mandatory = $true)] | |
[String]$WebsiteName | |
) | |
# Get the current subscription | |
$s = Get-AzureSubscription -Current | |
if (!$s) {throw "Cannot get Windows Azure subscription."} | |
#$thumbprint = $s.Certificate.Thumbprint | |
$thumbprint = $s.DefaultAccount # note: this only works when you have connected to azure using Import-AzurePublishSettingsFile | |
if (!$thumbprint) { throw "Cannot get subscription cert thumbprint."} | |
# Get the certificate of the current subscription from your local cert store | |
$cert = Get-ChildItem Cert:\CurrentUser\My\$thumbprint | |
if (!$cert) {throw "Cannot find subscription cert in Cert: drive."} | |
$website = Get-AzureWebsite -Name $WebsiteName | |
if (!$website) {throw "Cannot get Windows Azure website: $WebsiteName."} | |
# Compose the REST API URI from which you will get the publish settings info | |
$uri = "https://management.core.windows.net:8443/{0}/services/WebSpaces/{1}/sites/{2}/publishxml" -f ` | |
$s.SubscriptionId, $website.WebSpace, $Website.Name | |
# Get the publish settings info from the REST API | |
$publishSettings = Invoke-RestMethod -Uri $uri -Certificate $cert -Headers @{"x-ms-version" = "2013-06-01"} | |
if (!$publishSettings) {throw "Cannot get Windows Azure website publishSettings."} | |
return $publishSettings | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment