I've managed to start several blog post drafts with the intention of sharing a few of my PowerShell scripts - but haven't got around to finishing/posting any of them.
This actually led to an epiphany: the scripts I wanted to share all had an underlying theme: obtaining files using the Kudu Rest API using PowerShell.
Huh? Kudu?
Aw, a baby Kudu! |
If you don't already know, Kudu is the "engine behind git deployments" in Azure App Service - but can also be used as a built-in diagnostics tool within Azure. Any time you have an Azure website, you automatically get a 'companion' Kudu (aka SCM) site accessible via the following URL format: https://{ResourceName}.scm.azurewebsites.net.
For example, if your CM App Service name is
'mysitecoresite-xp2-small-prd1-cm',
the corresponding Kudu site would be:
https://mysitecoresite-xp2-small-prd1-cm.scm.azurewebsites.net/
If you've ever had to Rebuild the xDB index in Azure Search, Sitecore's documentation walks you through how to do so using the Kudu Debug console.
Kudu REST API
One of my favorite feature of Kudu is the Kudu REST API since any files you
can access via FTP are also accessible via the Kudu REST API.
You can download files, upload new ones, etc.
Typically, all you need are:
Typically, all you need are:
- Subscription ID
- Resource Group Name
- Resource Name
In Azure Portal - you can copy these values from a resource in the
overview panel:
Those values are the key to interact with the API using
PowerShell's Invoke-RestMethod.
There are a couple prerequisites:
There are a couple prerequisites:
- Azure RM module installed and ConnectAccount has been executed.
- Valid Azure credentials (same ones used to log into Azure Portal) to invoke Login-AzureRmAccount (converted to Base64)
Sitecore Azure Kudu Tools
I'd never written a PowerShell Module, but I figured this would be a great segway to learning how. I got to reading -- and tinkering -- and refactoring.
Before long I had written my first PowerShell Module: Sitecore Azure Kudu Tools.
Sitecore Azure Kudu Tools is a collection of functions (three at the time of this post) built to help you get information/files from Sitecore instances on hosted on Azure PaaS using the Kudu Rest API.
It's available on the PowerShell Gallery or check out the GitHub repository.
Sitecore Azure Kudu Tools is a collection of functions (three at the time of this post) built to help you get information/files from Sitecore instances on hosted on Azure PaaS using the Kudu Rest API.
It's available on the PowerShell Gallery or check out the GitHub repository.
Get-SitecoreSupportPackage
Allows you to remotely generate a Sitecore Support Package. The function
will download files defined for Sitecore Support Packages
into a specified path, obfuscate sensitive data from ConnectionStrings.config,
and compress the contents:\App_Config\* | Global.asax |
---|---|
\Logs\* | license.xml |
eventlog.xml | sitecore.version.xml |
Web.config |
Why?
While there's a built-in way to obtain Sitecore Support Packages in
Sitecore's admin page, being able to remotely obtain this information is a
nice alternative. This is useful not only for providing the required information for Sitecore Support tickets - but also for your own diagnostics.
Usage
Invoke this function using the following syntax:
Output
Alternatively, if you just run Get-SitecoreSupportPackage without any
parameters, you'll be prompted to provide each required parameter.
Invoke-SitecoreThumbprintValidation
Provides a way to verify that certificate thumbprints match across Sitecore
Azure PaaS Resource Group. The function will download
ConnectionStrings.config and AppSettings.config files from all App
Services in a given Resource Group, then display any certificate thumbprints
discrepancies.
Why?
If you've ever had to replace thumbprint values across an Azure PaaS Sitecore topology, you know that it can be a bit of a pain identifying all the configs where the old thumbprint needs to be replaced.Bram Stoop wrote a great post identifying all the places you'll need to modify those thumbprints. If you're looking to semi-automate this process, you can utilize the Kudu REST API to get all the configurations, then identify any mismatched thumbprint values using PowerShell.
Usage
Invoke this function using the following syntax:
Output
Get-SitecoreFileBackup
Allows you to a full copy of an App Service's website file contents. This function will download all files from in a given ResourceName.The following folders are excluded:
_DEV | sitecore modules |
App_Data | sitecore_files |
App_Browsers | temp |
sitecore | upload |
xsl |
Why?
Sometimes I just want everything. If I need to determine discrepancies between environments for any reason, this helps.Usage
Invoke this function using the following syntax:
Output
What's Next?
Now that the module is established, I've created a few GitHub Issues which I hope to get through quickly. I also plan to add more functions in the future and am 100% open to contributions.
Is it perfect? Far from it! It's a work in progress. Thrilled to share anyway.
Is it perfect? Far from it! It's a work in progress. Thrilled to share anyway.
If you're interested in contributing, please check out the contribute section on the Github repo.