#https://docs.microsoft.com/en-us/azure/virtual-machines/windows/ps-template Samples - #region PowerShellGet Module <# https://docs.microsoft.com/en-us/powershell/module/powershellget/Find-Module?view=powershell-5.1 With the latestPowerShellGetmodule, you can: •Search through items in the Gallery with Find-Module and Find-Script •Save items to your system from the Gallery with Save-Module and Save-Script •Install items from the Gallery with Install-Module and Install-Script •Upload items to the Gallery with Publish-Module and Publish-Script •Add your own custom repository with Register-PSRepository PowershellGet #> #endregion PowerShellGet Module # Find Module Find-Module -Name "Azure*" #Get all Cmdlets for Particular Module, with noun and verb. Get-Command -Module AzureRM -Verb Get -Noun AzureRMAvaila* #CTRL+M to Expand and Collapse # Install and Configure Azure Powershell #https://docs.microsoft.com/en-us/powershell/azure/install-azurerm-ps?view=azurermps-4.2.0 # Install the Azure Resource Manager modules from the PowerShell Gallery Install-Module AzureRM Install-Module -Name AzureAD Get-Module AzureADPreview Get-Module AzureAD # ----------------------------* # Script Login-AzureRmAccount # ----------------------------* #region Login-AzureRmAccount Login-AzureRmAccount Get-AzureRmSubscription Get-AzureRmSubscription -SubscriptionId "142a1ba9-4677-4e1e-b7c1-96baea282137" -TenantId "1a54e8e2-7a23-4bc6-84e5-173df62a4c4c" | Set-AzureRmContext #Or use the subscription Name Get-AzureRmSubscription -SubscriptionName "Free Trial" -TenantId "36035d42-64d3-4178-bec3-c585fad138ed" | Select-AzureRmSubscription | Set-AzureRmContext # To check the context anytime. Get-AzureRmContext <# SampleOutput Environment : AzureCloud Account : kparmar1263m@outlook.com TenantId : 1a54e8e2-7a23-4bc6-84e5-173df62a4c4c SubscriptionId : 142a1ba9-4677-4e1e-b7c1-96baea282137 SubscriptionName : Visual Studio Ultimate with MSDN CurrentStorageAccount : #> #To Get "Object ID" Get-AzureRmADUser #or Get-AzureRmADServicePrincipal #6e280366-7fe6-4977-ba0e-75f6c5c8f5f1 #endregion Login-AzureRmAccount # ----------------------------* # Script to get VM Related Commands # ----------------------------* Get-Command *AzureRmVM* <# CommandType Name Version S ----------- ---- ------- - Cmdlet Add-AzureRmVMAdditionalUnattendContent 3.2.1 A Cmdlet Add-AzureRmVMDataDisk 3.2.1 A Cmdlet Add-AzureRmVMNetworkInterface 3.2.1 A Cmdlet Add-AzureRmVMSecret 3.2.1 A Cmdlet Add-AzureRmVmssAdditionalUnattendContent 3.2.1 A Cmdlet Add-AzureRmVmssDataDisk 3.2.1 A Cmdlet Add-AzureRmVmssDiagnosticsExtension 3.2.1 A Cmdlet Add-AzureRmVmssExtension 3.2.1 A Cmdlet Add-AzureRmVMSshPublicKey 3.2.1 A Cmdlet Add-AzureRmVmssNetworkInterfaceConfiguration 3.2.1 A Cmdlet Add-AzureRmVmssSecret 3.2.1 A Cmdlet Add-AzureRmVmssSshPublicKey 3.2.1 A Cmdlet Add-AzureRmVmssWinRMListener 3.2.1 A Cmdlet ConvertTo-AzureRmVMManagedDisk 3.2.1 A Cmdlet Disable-AzureRmVMDiskEncryption 3.2.1 A Cmdlet Get-AzureRmVM 3.2.1 A Cmdlet Get-AzureRmVMAccessExtension 3.2.1 A Cmdlet Get-AzureRmVMADDomainExtension 3.2.1 A Cmdlet Get-AzureRmVMAEMExtension 3.2.1 A Cmdlet Get-AzureRmVMBootDiagnosticsData 3.2.1 A Cmdlet Get-AzureRmVMChefExtension 3.2.1 A Cmdlet Get-AzureRmVMCustomScriptExtension 3.2.1 A Cmdlet Get-AzureRmVMDiagnosticsExtension 3.2.1 A Cmdlet Get-AzureRmVMDiskEncryptionStatus 3.2.1 A Cmdlet Get-AzureRmVMDscExtension 3.2.1 A Cmdlet Get-AzureRmVMDscExtensionStatus 3.2.1 A Cmdlet Get-AzureRmVMExtension 3.2.1 A Cmdlet Get-AzureRmVMExtensionImage 3.2.1 A Cmdlet Get-AzureRmVMExtensionImageType 3.2.1 A Cmdlet Get-AzureRmVMImage 3.2.1 A Cmdlet Get-AzureRmVMImageOffer 3.2.1 A Cmdlet Get-AzureRmVMImagePublisher 3.2.1 A Cmdlet Get-AzureRmVMImageSku 3.2.1 A Cmdlet Get-AzureRmVMSize 3.2.1 A Cmdlet Get-AzureRmVMSqlServerExtension 3.2.1 A Cmdlet Get-AzureRmVmss 3.2.1 A Cmdlet Get-AzureRmVmssSku 3.2.1 A Cmdlet Get-AzureRmVmssVM 3.2.1 A Cmdlet Get-AzureRmVMUsage 3.2.1 A Cmdlet New-AzureRmVM 3.2.1 A Cmdlet New-AzureRmVMConfig 3.2.1 A Cmdlet New-AzureRmVMSqlServerAutoBackupConfig 3.2.1 A Cmdlet New-AzureRmVMSqlServerAutoPatchingConfig 3.2.1 A Cmdlet New-AzureRmVMSqlServerKeyVaultCredentialConfig 3.2.1 A Cmdlet New-AzureRmVmss 3.2.1 A Cmdlet New-AzureRmVmssConfig 3.2.1 A Cmdlet New-AzureRmVmssIpConfig 3.2.1 A Cmdlet New-AzureRmVmssVaultCertificateConfig 3.2.1 A Cmdlet Publish-AzureRmVMDscConfiguration 3.2.1 A Cmdlet Remove-AzureRmVM 3.2.1 A Cmdlet Remove-AzureRmVMAccessExtension 3.2.1 A Cmdlet Remove-AzureRmVMAEMExtension 3.2.1 A Cmdlet Remove-AzureRmVMBackup 3.2.1 A Cmdlet Remove-AzureRmVMChefExtension 3.2.1 A Cmdlet Remove-AzureRmVMCustomScriptExtension 3.2.1 A Cmdlet Remove-AzureRmVMDataDisk 3.2.1 A Cmdlet Remove-AzureRmVMDiagnosticsExtension 3.2.1 A Cmdlet Remove-AzureRmVMDiskEncryptionExtension 3.2.1 A Cmdlet Remove-AzureRmVMDscExtension 3.2.1 A Cmdlet Remove-AzureRmVMExtension 3.2.1 A Cmdlet Remove-AzureRmVMNetworkInterface 3.2.1 A Cmdlet Remove-AzureRmVMSecret 3.2.1 A Cmdlet Remove-AzureRmVMSqlServerExtension 3.2.1 A Cmdlet Remove-AzureRmVmss 3.2.1 A Cmdlet Remove-AzureRmVmssDataDisk 3.2.1 A Cmdlet Remove-AzureRmVmssDiagnosticsExtension 3.2.1 A Cmdlet Remove-AzureRmVmssExtension 3.2.1 A Cmdlet Remove-AzureRmVmssNetworkInterfaceConfiguration 3.2.1 A Cmdlet Restart-AzureRmVM 3.2.1 A Cmdlet Restart-AzureRmVmss 3.2.1 A Cmdlet Save-AzureRmVMImage 3.2.1 A Cmdlet Set-AzureRmVM 3.2.1 A Cmdlet Set-AzureRmVMAccessExtension 3.2.1 A Cmdlet Set-AzureRmVMADDomainExtension 3.2.1 A Cmdlet Set-AzureRmVMAEMExtension 3.2.1 A Cmdlet Set-AzureRmVMBackupExtension 3.2.1 A Cmdlet Set-AzureRmVMBginfoExtension 3.2.1 A Cmdlet Set-AzureRmVMBootDiagnostics 3.2.1 A Cmdlet Set-AzureRmVMChefExtension 3.2.1 A Cmdlet Set-AzureRmVMCustomScriptExtension 3.2.1 A Cmdlet Set-AzureRmVMDataDisk 3.2.1 A Cmdlet Set-AzureRmVMDiagnosticsExtension 3.2.1 A Cmdlet Set-AzureRmVMDiskEncryptionExtension 3.2.1 A Cmdlet Set-AzureRmVMDscExtension 3.2.1 A Cmdlet Set-AzureRmVMExtension 3.2.1 A Cmdlet Set-AzureRmVMOperatingSystem 3.2.1 A Cmdlet Set-AzureRmVMOSDisk 3.2.1 A Cmdlet Set-AzureRmVMPlan 3.2.1 A Cmdlet Set-AzureRmVMSourceImage 3.2.1 A Cmdlet Set-AzureRmVMSqlServerExtension 3.2.1 A Cmdlet Set-AzureRmVmss 3.2.1 A Cmdlet Set-AzureRmVmssBootDiagnostic 3.2.1 A Cmdlet Set-AzureRmVmssOsProfile 3.2.1 A Cmdlet Set-AzureRmVmssStorageProfile 3.2.1 A Cmdlet Set-AzureRmVmssVM 3.2.1 A Cmdlet Start-AzureRmVM 3.2.1 A Cmdlet Start-AzureRmVmss 3.2.1 A Cmdlet Stop-AzureRmVM 3.2.1 A Cmdlet Stop-AzureRmVmss 3.2.1 A Cmdlet Test-AzureRmVMAEMExtension 3.2.1 A Cmdlet Update-AzureRmVM 3.2.1 A Cmdlet Update-AzureRmVmss 3.2.1 A Cmdlet Update-AzureRmVmssInstance 3.2.1 A #> Get-AzureRmVM <# ResourceGroupName Name Location VmSize OsType NIC ----------------- ---- -------- ------ ------ --- KR1 KWeb1 eastus Standard_DS1 Windows kweb1904 KR1 KWeb1-Backup eastus Standard_DS1 Windows ...72d4afe3e38fb7b #> help Stop-AzureRmVM -Examples Stop-AzureRmVM -ResourceGroupName "KR1" -Name "KWeb1" help Stop-AzureRmVM -Examples # ----------------------------* # Azure Modules # ----------------------------* #region AzureModules Check #Azure PowerShell module version 3.6 is required, use below to find out. Get-Module -ListAvailable AzureRM #otherwise install it from here #https://docs.microsoft.com/en-us/powershell/azure/install-azurerm-ps?view=azurermps-4.2.0 # To check available Azure PowerShell module Get-Module -ListAvailable Azure* | Select-Object Name, Version, Path Get-Module -ListAvailable AzureRM* | Select-Object Name, Version, Path Get-Module -ListAvailable AzureAD* | Select-Object Name, Version, Path # To check if Azure PowerShellGet module is installed #https://docs.microsoft.com/en-us/powershell/azure/install-azurerm-ps?view=azurermps-4.2.0 Get-Module PowerShellGet -list | Select-Object Name,Version,Path <# SampleOutput-PowerShellGet Name Version Path ---- ------- ---- PowerShellGet 1.0.0.1 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PowerShellGet.psd1 #> #endregion AzureModules Check Get-Module <# PS C:\Users\kparmar> Get-Module ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Manifest 3.2.1 AzureRM.Profile {Add-AzureRmAccoun... Script 1.0.0.0 ISE {Get-IseSnippet, I... Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add... Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-T... #> Get-Module AzureRM # Below gives version of Module - AzureRM (in this case) Get-Module AzureRM -list | Select-Object Name,Version,Path <# Name Version Path ---- ------- ---- AzureRM 4.2.1 C:\Program Files\WindowsPowerShell\Modules\AzureRM\4.2.1\Azu... #What other modules in Azure are available ? #•Azure Active Directory Install-Module AzureAD Install-module AzureADPreview Install-module AADRM Install-module AzureInformationProtection Install-module RMSProtection Install-module Service Fabric Install-module ElasticDB #> # ----------------------------* # Script Create Azure Availability Set # ----------------------------* #region Create Azure Availability Set Install-Module AzureRM.Compute -RequiredVersion 2.6.0 #If you are using managed disks for your VMs, type: New-AzureRmAvailabilitySet -ResourceGroupName "myResourceGroup" -Name "myAvailabilitySet" -Location "West US" -managed #If you are using your own storage accounts for your VMs, type: New-AzureRmAvailabilitySet -ResourceGroupName "myResourceGroup" -Name "myAvailabilitySet" -Location "West US" #endregion Create Azure Availability Set