Kudu zip deployment

$SiteName = "webapp"
$SitePassword = "You can get it from publish profile"
$ApiUrl = "https://$SiteName.scm.azurewebsites.de/api/zipdeploy"
$ArchivePath = "WebApp.zip"

$Base64 = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "`$$SiteName", $SitePassword)))
$Headers = @{Authorization=("Basic {0}" -f $Base64)}
Invoke-RestMethod -Uri $ApiUrl `
                  -Headers $Headers `
                  -UserAgent "powershell/1.0" `
                  -Method POST -InFile $ArchivePath `
                  -ContentType "multipart/form-data"

Git pull vs fetch

git pull = git fetch + git merge

Find Azure resource across all subscriptions

Get-AzSubscription | % {
  Select-AzSubscription $_
  Get-AzResource | Where-Object {$_.Name -match "<resource name>"} | Select-Object *

Load Azure PowersShell on the fly

Sometimes installing modules on the system is not an option. E.g. build servers or any kind of machines where you want to run non-standard cmdlet but you don't want to (or not allowed to) install anything.

In order to do it you need three files.

load.ps1 - does the heavy lifting. Just look at the script. Everything works pretty straight forward.

$modulesPath = ".\modules"

# Cleanup
Remove-Module Az*
Remove-Item -Path $modulesPath -Force -Recurse

# Download nuget.exe in case you don't have it
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "nuget.exe"

# Restore packages from PowerShell Gallery
& ".\nuget.exe" "restore" "packages.config" "-packagesdirectory" $modulesPath

# Remove version portion from each package folder (otherwise system will not recognize modules)
Get-ChildItem $modulesPath -Directory | % { 
    Rename-Item -Path $_.FullName -NewName $($_.Name -replace "\.\d+\.\d+\.\d+","") 

# Add our module folder to the system modules path
$env:PSModulePath += ";$(Resolve-Path -Path $modulesPath)"

# Import Az module
Import-Module Az

nuget.config - defines package source. By default nuget.exe will use nuget.org or any other repository defined on a user/system level. The chances that it already has PowerShell Gallery in it is pretty low (at least in the environments I work with).

<?xml version="1.0" encoding="utf-8"?>
    <add key="powershellgallery.com" value="https://www.powershellgallery.com/api/v2/" protocolVersion="2" />
    <add key="signatureValidationMode" value="Accept" />

packages.config - holds the list of packages. In our case we're getting Az 2.8.0 but it can be adjusted to download virtually any number/kind of modules (don't forget to add Import-Module statements for any other module(s) you add).

<?xml version="1.0" encoding="utf-8"?>
    <package id="Az" version="2.8.0" />
    <package id="Az.Accounts" version="1.6.4" />
    <package id="Az.Advisor" version="1.0.1" />
    <package id="Az.Aks" version="1.0.2" />
    <package id="Az.AnalysisServices" version="1.1.1" />
    <package id="Az.ApiManagement" version="1.3.2" />
    <package id="Az.ApplicationInsights" version="1.0.2" />
    <package id="Az.Automation" version="1.3.4" />
    <package id="Az.Batch" version="1.1.2" />
    <package id="Az.Billing" version="1.0.1" />
    <package id="Az.Cdn" version="1.3.1" />
    <package id="Az.CognitiveServices" version="1.2.1" />
    <package id="Az.Compute" version="2.7.0" />
    <package id="Az.ContainerInstance" version="1.0.1" />
    <package id="Az.ContainerRegistry" version="1.1.0" />
    <package id="Az.DataFactory" version="1.4.0" />
    <package id="Az.DataLakeAnalytics" version="1.0.1" />
    <package id="Az.DataLakeStore" version="1.2.3" />
    <package id="Az.DeploymentManager" version="1.0.1" />
    <package id="Az.DevTestLabs" version="1.0.0" />
    <package id="Az.Dns" version="1.1.1" />
    <package id="Az.EventGrid" version="1.2.2" />
    <package id="Az.EventHub" version="1.4.0" />
    <package id="Az.FrontDoor" version="1.1.1" />
    <package id="Az.HDInsight" version="2.0.2" />
    <package id="Az.HealthcareApis" version="1.0.0" />
    <package id="Az.IotHub" version="1.3.1" />
    <package id="Az.KeyVault" version="1.3.1" />
    <package id="Az.LogicApp" version="1.3.1" />
    <package id="Az.MachineLearning" version="1.1.1" />
    <package id="Az.ManagedServices" version="1.0.1" />
    <package id="Az.MarketplaceOrdering" version="1.0.1" />
    <package id="Az.Media" version="1.1.0" />
    <package id="Az.Monitor" version="1.4.0" />
    <package id="Az.Network" version="1.15.0" />
    <package id="Az.NotificationHubs" version="1.1.0" />
    <package id="Az.OperationalInsights" version="1.3.3" />
    <package id="Az.PolicyInsights" version="1.1.3" />
    <package id="Az.PowerBIEmbedded" version="1.1.0" />
    <package id="Az.RecoveryServices" version="1.4.5" />
    <package id="Az.RedisCache" version="1.1.1" />
    <package id="Az.Relay" version="1.0.2" />
    <package id="Az.Resources" version="1.7.0" />
    <package id="Az.ServiceBus" version="1.4.0" />
    <package id="Az.ServiceFabric" version="1.2.0" />
    <package id="Az.SignalR" version="1.1.0" />
    <package id="Az.Sql" version="1.15.0" />
    <package id="Az.Storage" version="1.8.0" />
    <package id="Az.StorageSync" version="1.2.1" />
    <package id="Az.StreamAnalytics" version="1.0.0" />
    <package id="Az.TrafficManager" version="1.0.2" />
    <package id="Az.Websites" version="1.5.0" />

Git cheatsheet

Update existing commit

git commit --amend --no-edit
git push --force 

Remove all local changes

git clean -fdx

Mirror repositories

git clone --mirror <source.repository>
cd source.repository.git
git push --mirror <target.repository>

Update submodules

git submodule update --init --recursive --progress

Remove last commit

git reset --soft HEAD~1
git reset --hard HEAD~1

Reset file

git checkout -- <path>

Merge changes as a single commit

git merge --squash <source branch>
git commit --message "merge commit message"

Get remote changes and apply local changes

git stash
git pull --rebase origin <source branch>
git stash pop