Azure recipes


See also: all the recipes and the intro

# docs about Azure VMs
https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-disks-vhds/

# Azure PowerShell tools
https://azure.microsoft.com/en-us/downloads/

# How to upload a VHD to Azure
https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-create-upload-vhd-windows-server/

# How to acess HTTP PowerShell in Azure
http://michaelwasham.com/windows-azure-powershell-reference-guide/introduction-remote-powershell-with-windows-azure/
# Script to install the Azure root cert on machines that will be connecting to
# Azure VMs by HTTPS
https://gallery.technet.microsoft.com/scriptcenter/Configures-Secure-Remote-b137f2fe

# How to set up a domain in Azure
Creating an Azure Virtual Network Complete with Domain Controller, Active Directory and SharePoint
https://github.com/Azure/azure-quickstart-templates/tree/master/201-vm-domain-join # Azure key vault intro (kind of crappy) http://blogs.technet.com/b/kv/archive/2015/01/09/azure-key-vault-step-by-step.aspx
Securing Azure Web Job Secrets with Azure Key Vault
https://github.com/Azure/azure-sdk-for-net/tree/master/src/KeyVault/Microsoft.Azure.KeyVault.Samples # Example of exporting X509 certs to Azure key vault http://blogs.msdn.com/b/cclayton/archive/2012/03/21/windows-azure-and-x509-certificates.aspx # Azure ARM storage management & blobs https://azure.microsoft.com/en-us/documentation/articles/storage-powershell-guide-full/ # Azure blob shared access tokens https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-shared-access-signature-part-1/ https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-shared-access-signature-part-2/ # Azure ARM creating a VM from customer's image: # upload a VHD to the ARM storage account, either through Powershell or through Azure Storage Explorer and run https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-from-user-image # Azure CRP VM image creation https://azure.microsoft.com/en-us/documentation/templates/101-vm-from-user-image/ http://codeisahighway.com/how-to-create-a-virtual-machine-from-a-custom-image-using-an-arm-template/ http://codeisahighway.com/how-to-create-a-virtual-machine-from-a-custom-image-using-arm-api-and-powershell/ http://codeisahighway.com/how-to-capture-your-own-custom-virtual-machine-image-under-azure-resource-manager-api/ # Azure CRP templates syntax https://azure.microsoft.com/en-us/documentation/articles/resource-group-authoring-templates/#expressions-and-functions # VM Agent https://azure.microsoft.com/en-us/blog/vm-agent-and-extensions-part-1/ https://azure.microsoft.com/en-us/blog/vm-agent-and-extensions-part-2/ # Azure VM extensions/plugins https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-extensions-features/
Introducing the Azure PowerShell DSC (Desired State Configuration) extension
https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-classic-manage-extensions/
Custom Script extension for ARM VMs in Azure
# Azure storage https://azure.microsoft.com/en-us/documentation/articles/storage-powershell-guide-full/ https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-shared-access-signature-part-2/ # connect to the Azure account, once Add-AzureAccount # configuring the Azure session, for uploading files Get-AzurePublishSettingsFile # do once, downloads the file, may need to change the date on the file name in the next command $sub = Import-AzurePublishSettingsFile "c:\tmp\My Subscription-9-24-2015-credentials.publishsettings" # for Azure ARM Login-AzureRmAccount # upload a VHD Add-AzureVhd -Destination "https://mystore.blob.core.windows.net/mycontainer/image74.vhd" -LocalFilePath C:\vm\myimage.vhd # register the VHD as a custom VM image Add-AzureVMImage -ImageName "rtm_74" -MediaLocation "https://mystore.blob.core.windows.net/mycontainer/image74.vhd" -OS Windows # create a VM from script New-AzureQuickVM -Windows -ImageName "rtm_74" -Name sbn74 -ServiceName sbn74 -AdminUsername me -CustomDataFile "c:\tmp\bcd.txt" -EnableWinRMHttp -Password "password" -Location "Central US" # Settings for PowerShell login with HTTPS, the tool is downloaded from https://gallery.technet.microsoft.com/scriptcenter/Configures-Secure-Remote-b137f2fe C:\work\AzureNano\CertManagement\InstallWinRMCertAzureVM.ps1 -Sub "My Subscription" -Ser sbn74 -Name sbn74 enter-pssession -ConnectionUri https://sbn74.cloudapp.net:5986/WSMAN -Credential "me" # Azure VM extensions https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-classic-manage-extensions/ # get the list of available extensions # (but doesn't include for example DSC) Get-AzureServiceAvailableExtension # Azure DSC extension
Introducing the Azure PowerShell DSC (Desired State Configuration) extension
# config file C:\tmp\IISInstall.ps1 configuration IISInstall {     node (“localhost”)     {         WindowsFeature IIS         {             Ensure = “Present”             Name = “Web-Server”         }     } } # config file C:\tmp\IISInstall.ps1 # a new VM with the extension Publish-AzureVMDscConfiguration -ConfigurationPath C:\tmp\IISInstall.ps1 Get-AzureStorageBlob -Container windows-powershell-dsc $vm = New-AzureVMConfig -Name “example-1” -InstanceSize Small -ImageName “a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-201407.01-en.us-127GB.vhd” $vm = Add-AzureProvisioningConfig -VM $vm -Windows -AdminUsername “admin_account” -Password “password” $vm = Set-AzureVMDSCExtension -VM $vm -ConfigurationArchive “IISInstall.ps1.zip” -ConfigurationName “IISInstall” New-AzureVM -VM $vm -Location “West US” -ServiceName “example-1-svc” -WaitForBoot # adding/changing an extension to a VM $vm = Get-AzureVM -Name “example-1” -ServiceName “example-1-svc” $vm = Set-AzureVMDSCExtension -VM $vm -ConfigurationArchive “FourthCoffee.ps1.zip” -ConfigurationName “FourthCoffee” $vm | Update-AzureVM # configuring the CustomExtension in my test VM Set-AzureStorageBlobContent -File C:\tmp\runme.ps1 -Container windows-powershell-dsc Get-AzureStorageBlob -Container windows-powershell-dsc # list the blobs $vm = Get-AzureVM -Name "myvm" -ServiceName "myvm" $vm = Set-AzureVMCustomScriptExtension -VM $vm -ContainerName "windows-powershell-dsc" -FileName "runme.ps1" -Run "runme.ps1" -Argument "myarg3 myarg4 >c:\custom.log" $vm | Update-AzureVM Get-AzureVMCustomScriptExtension -vm $vm # configuring the CustomExtension in my test VM in ARM New-NanoServerAzureVM -Location westus -vmname myn75 -AdminUsername me -AdminPassword (ConvertTo-SecureString -Force -AsPlainText "password") -ResourceGroupName mykv2 -VaultName myvault $sac = New-AzureRmStorageAccount -ResourceGroupName mykv2 -name myscript -SkuName Standard_LRS -Location westus $sac = Get-AzureRmStorageAccount -ResourceGroupName mykv2 -name myscript $mycont = New-AzureStorageContainer -Name myscriptc -Context $sac.Context $mycont = Get-AzureStorageContainer -Name myscriptc -Context $sac.Context Set-AzureStorageBlobContent -File C:\tmp\runme.ps1 -Container myscriptc -Context $sac.Context Get-AzureStorageBlob -Container myscriptc -Context $sac.Context $uri = New-AzureStorageBlobSASToken -Container myscriptc -Blob runme.ps1 -Permission r -ExpiryTime ((Get-Date).AddDays(1.0)) -Context $sac.Context -FullUri # wget $uri # $PrivateConfiguration = @{ #     storageAccountName="$ScriptBlobAccount"; #     storageAccountKey="$ScriptBlobKey"; # } $PrivateConfiguration = @{     # commandToExecute can go here, fileUris can't } $PublicConfiguration = @{     fileUris=@(,[string]$uri);     commandToExecute="powershell.exe -ExecutionPolicy Unrestricted -File runme.ps1 poiuyt 444 >c:\runme.log"; } Set-AzureRmVMExtension -ResourceGroupName mykv2 -VMName myn75 -Location westus -Name CustomScript1 -Publisher Microsoft.Compute -ExtensionType CustomScriptExtension -TypeHandlerVersion 1.8 -Settings $PublicConfiguration -ProtectedSettings $PrivateConfiguration -Verbose -Debug

 

 

Comments (0)

Skip to main content