Extract Publishing Profile Username and Password using PowerShell
While deploying an Azure Web App recently, I wanted to automate the deployment of getting the publishing profile username and password information to allow me to use a Kudu zipdeploy action to upload the site.
Using a combination of AzureRm PowerShell cmdlets and a little XPath, I was able to extract the username and password which I could then formalise in to basic authorisation headers for use with the Kudu API. In fact, I saw very few examples of doing this end-to-end.
1 2 3 4 5 6 7 8 9 10 11 12 |
$siteName = 'myazurewebsite' $ResourceGroupName = 'MyAzureResourceGroup' $PublishingProfile = [xml](Get-AzureRmWebAppPublishingProfile -ResourceGroupName $ResourceGroupName -Name $siteName) $Username = (Select-Xml -Xml $PublishingProfile -XPath "//publishData/publishProfile[contains(@profileName,'Web Deploy')]/@userName").Node.Value $Password = (Select-Xml -Xml $PublishingProfile -XPath "//publishData/publishProfile[contains(@profileName,'Web Deploy')]/@userPWD").Node.Value $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Username,$Password))) $apiUrl = "https://$siteName.scm.azurewebsites.net/api/zipdeploy"; Invoke-RestMethod -Uri $apiUrl -InFile 'D:\site.zip' -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method Post -ContentType "multipart/form-date"; |
Another one for the scrapbook.
-Lewis
Exactly what I was looking for. Thanks!
Yep exactly what I was looking for