Create an Azure site using PowerShell and FTP

I need to write a PowerShell script that automatically creates an Azure Website and deploys the contents of the local file system. It looks like the Azure PowerShell SDK doesn't provide a way to copy files to the site, so we want to use FTP as our deployment method.

To get the correct FTP endpoints and credentials, the only way I have found is to call the Azure Management Rest API: Get Site Publishing Profile .

But this API, like another Azure Management API, requires a certificate. I found the following tutorial Creating Real-World Cloud Applications with Windows Azure that explains how to get a certificate:

$s = Get-AzureSubscription -Current
$thumbprint = $s.Certificate.Thumbprint

      

Unfortunately it looks like with the current SDK $s.Certificate

it is always null, this property does not exist. If I manually set the certificate thumbprint everything works as expected.

Do you have an idea on how to get the correct subscription certificate? Or do you have an easy alternative to deploy on-premises files to an Azure website?

+3


source to share


1 answer


It seems you can now access the thumbprint of the certificate with

$thumbprint = $s.DefaultAccount

      

instead

#$thumbprint = $s.Certificate.Thumbprint

      

It seems that the DefaultAccount has the same meaning as the thumbprint of the certificate.

For reference only, here is my complete script to get the publish profile for a given website:



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 #this code doesn't work anymore
    $thumbprint = $s.DefaultAccount
    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
}

      

NOTE: this only works when you connected to azure using Import-AzurePublishSettingsFile

Can anyone confirm that it is safe to use the property DefaultAccount

?

UPDATE

If you're using the Kudu API to load your site like this , you don't need a certificate or profile publication. You should read the username and password using Get-AzureWebsite

, and the hostname is simple yourwebsitename.scm.azurewebsites.net

(note the scm segment). I suggest using Kudu because it is much more reliable and faster.

+1


source







All Articles