Skip to content

Cheat sheet – Azure websites (Web Apps) – PowerShell Cmdlets

Friends,

Here is the list of the important Azure Cmdlets for Azure websites.Hope it will be useful for you

COMMAND

COMMENT

Get-AzureWebsiteLocationTo determine the website locations that are available to your Azure subscription
$wsName = “techexperiments-web”

Get-Azurewebsite –Name=$wsName

Gets all azure websites in the current subscription and returns basic information. When parameter –name is used it returns an object with extensive information including configuration details.
$wsName = “techexperiments-web”

Get-AzureWebsiteDeployment -Name $wsName

Gets the deployments for the specific website
$wsName = “techexperiments-web”

Get-AzureWebsiteJob –Name $wsName

Gets all the jobs associated with the website
$wsName = “techexperiments-web”

$wjName = ” techexperiments-WebJob”

Get-AzureWebsiteJobHistory -Name $wsName –JobName $wjName

Gets the complete history of the specific web job
$wsName = “techexperiments-web”

Get-AzureWebsiteLog -Name $wsName

Gets the log for the specified website
$wsName = “techexperiments-web”

Get-AzureWebsiteMetric -Name $wsName -StartDate (get-date).AddHours(-2) -MetricNames “Requests” -InstanceDetails -SlotView -TimeGrain “PT1M”

Gets the metrics for the website for the specific website for the specific parameter.
Test-AzureName -Website “techexperiments-web”To determine if an Azure website name already exists. The result will be either true or false
$wsLocation = “East US”

$wsName = ” techexperiments-web”

New-AzureWebsite -Location $wsLocation -Name $wsName

To create the website, use the New-Azure Website Cmdlets, specifying the location and

name parameters

$wsLocation = “East US”

$wsName = ” techexperiments-web”

$wsQASlot = “QA”

New-AzureWebsite -Location $wsLocation -Name $wsName -Slot $wsQASlot

To create a deployment slot using the Azure PowerShell cmdlets, use the New-AzureWebsite

cmdlet and provide the name of the existing website in the Name parameter, and the name of the new deployment slot in the Slot parameter.

$wsName = ” techexperiments-web”

$wsStaging = “Staging”

$wsProduction = “Production”

Switch-AzureWebsiteSlot -Name $wsName -Slot1 $wsStaging -Slot2 $wsProduction

To swap the slots specified in the Slot1 and Slot2 parameters.
$pkgPath = “G:\techexperiments -Web.zip”

Publish-AzureWebsiteProject -Name $wsName -Slot $wsStaging -Package $pkgPath

Publishing a web deployment package using Azure PowerShell
$wjPath = “G:\techexperiments-WebJob.exe”

$wjName = ” techexperiments-WebJob”

New-AzureWebsiteJob -Name $wsName -JobName $wjName -JobType Triggered -Slot $wsStaging

-JobFile $wjPath

Deploying an Azure WebJob using Azure PowerShell
$wsName = ” techexperiments-web”

Set-AzureWebsite $wsName -WebSocketsEnabled $true

To specify site settings using Azure PowerShell, use the Set-AzureWebsite cmdlet
$settings = New-Object Hashtable

$settings[“techexperiments_Sales_WebService_URL”] = “https:// techexperiments-webservices/sales

Set-AzureWebsite $wsName -AppSettings $settings

To define application settings using PowerShell, you will need to create a hashtable to define the setting and then use the cmd settings.
$connString = (@{Name=”techexperimentsdb”; Type=”SQLAzure”; ConnectionString=”Server=tcp:..” })

Set-AzureWebsite -Name $wsName -ConnectionStrings $connString

To define a connection string using Azure PowerShell where a

connString structure is used to define the connection string

Set-AzureWebsite -Name ” techexperiments-web” -HostNames @(www.techexperiments.com, ” techexperiments.com”)To add the custom domain using the Set-AzureWebsite cmdlet
New-AzureTrafficManagerProfile -Name techexperimentsTM `

-DomainName techexperiments-web-tm.trafficmanager.net -LoadBalancingMethod Failover `

-MonitorPort 80 -MonitorProtocol Http -MonitorRelativePath “/” -Ttl 30

To create a profile named techexperimentsTM with a domain name of techexperiments-web-tm.traficmanager.net,

and a Failover load balancing method

$tmProfile = Get-AzureTrafficManagerProfile -Name ” techexperimentsTM”

Add-AzureTrafficManagerEndpoint -TrafficManagerProfile $tmProfile `

-DomainName ” techexperiments-web-west.azurewebsites.net” -Type AzureWebsite `

-Status Enabled |

Set-AzureTrafficManagerProfile

You can use Azure PowerShell to add an endpoint by using the Get-AzureTraficManagerProile,Add-AzureTraficManagerEndpoint, and Set-AzureTraficManagerProile cmdlets
$tmProfile = Get-AzureTrafficManagerProfile -Name ” techexperimentsTM”

Remove-AzureTrafficManagerEndpoint -TrafficManagerProfile $tmProfile `

-DomainName ” techexperiments-web-west.azurewebsites.net” |

Set-AzureTrafficManagerProfile

To remove an endpoint, use this cmdlet
$tmProfile = Get-AzureTrafficManagerProfile -Name ” techexperimentsTM”

Set-AzureTrafficManagerEndpoint -TrafficManagerProfile $tmProfile `

-DomainName ” techexperiments-web-west.azurewebsites.net” -Status Disabled |

Set-AzureTrafficManagerProfile

To disable an endpoint, use the Set-AzureTraficManagerEndpoint cmdlet
$wsName = ” techexperiments-web”

$handlerMapping = New-Object Microsoft.WindowsAzure.Commands.Utilities.Websites.

Services.WebEntities.HandlerMapping

$handlerMapping.Extension = “*.php”

$handlerMapping.ScriptProcessor = “d:\home\site\wwwroot\bin\php54\php-cgi.exe”

Set-AzureWebsite -Name $wsName -HandlerMappings $handlerMapping

Use the Set-AzureWebsite cmdlet and pass the handler mapping in using the HandlerMappings parameter. The script below demonstrates adding a handler mapping for *.php files
$wsName = ” techexperiments-web”

Set-AzureWebsite -Name $wsName -RequestTracingEnabled $true -HttpLoggingEnabled $true

Enable and disable diagnostic logs using the Set-AzureWebsite cmdlet. As an example, the code shown here enables the web server logging and the failed request tracing
$wsName = ” techexperiments-web”

Save-AzureWebsiteLog -Name $wsName -Output g:\weblogs.zip

You can download all the log files using the Azure PowerShell as

Shown. This code will download the log files and store them in EG:\Weblogs.zip on the client computer.

Get-AzureWebsiteLog -Name “techexperiments-web-west” -Tail -Path httpyou can stream logs directly in the Azure PowerShell

Console window. The code shown here connects to the log-streaming service to start streaming the web server logs.

Get-AzureWebsiteLog -Name ” techexperiments-web-west” -Tail -Message ErrorThe Get-AzureWebsiteLog also supports a Message parameter that you can use to filter the output when streaming application logs. For example, the code shown here filters the log-streaming output to just application logs that are categorized as errors
Published inAzurePowerShell

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *