SHIFT-WIKI

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


azurepowershell

Azure PowerShell

Azure PowerShell can be used to manage Azure Resources, and because it provides more functionality then the web interface you really can't without. This tutorial shows you how to install and use it on a Windows 10 professional installation. Note that this already has a PowerShell included.

Note: Azure Powershell, as Azure as a whole has two versions, each for managing a different Azure version. The normal Azure PowerShell cmdlets are for managing the classic portal, https://manage.windowsazure.com , the AzureRM PowerShell cmdlets are for managing the Azure Resource Manager on https://portal.azure.com .

Download the Installer

Download the installer from http://aka.ms/webpi-azps and run it keeping all the defaults.

Connect to Your Azure Account

Use the Login-AzureRmAccount cmdlet to logon to your account. The cmdlet will ask you for your credentials but if you don't want to provide them every time you cab store them in a variable:

PS C:\Users\sjoer> Login-AzureRmAccount
WARNING: Microsoft Azure PowerShell collects data about how users use PowerShell cmdlets and some problems they
encounter.  Microsoft uses this information to improve our PowerShell cmdlets.  Participation is voluntary and when you
 choose to participate your device automatically sends information to Microsoft about how you use Azure PowerShell.
 
If you choose to participate, you can stop at any time by using Azure PowerShell as follows:
1. Use the Disable-AzureDataCollection cmdlet to turn the feature Off. The cmdlet can be found in the
AzureResourceManager module
To disable data collection: PS > Disable-AzureDataCollection
 
If you choose to not participate, you can enable at any time by using Azure PowerShell as follows:
1. Use the Enable-AzureDataCollection cmdlet to turn the feature On. The cmdlet can be found in the
AzureResourceManager module
To enable data collection: PS > Enable-AzureDataCollection
 
Select Y to enable data collection [Y/N]:
WARNING: You choose not to participate in Microsoft Azure PowerShell data collection.
WARNING: The setting profile has been saved to the following path 'C:\Users\sjoer\AppData\Roaming\Windows Azure Powershell\AzureDataCollectionProfile.json'.
 
 
Environment               : AzureCloud
Account                   : sjoerd.hooft@xxxxx.com
TenantId                  : wwwwwwww-2222-dddd-4444-jjjjjjjjjjjjjj
SubscriptionId            : xxxxxxxx-yyyy-zzzz-wwww-aaaaaaaaaaaa
SubscriptionName          : Visual Studio Enterprise
CurrentStorageAccount     :
Note that the first time you use this you might be asked if you agree that Microsoft collects data on you.

View Installed Azure PowerShell Modules

PS C:\Users\sjoer> get-module -listavailable Azure*
 
 
    Directory: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager
 
 
ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   0.0.3      AzureRM.AnalysisServices            {Resume-AzureRmAnalysisServicesServer, Suspend-AzureRmAnal...
Manifest   3.3.0      AzureRM.ApiManagement               {Add-AzureRmApiManagementRegion, Get-AzureRmApiManagementS...
Manifest   2.5.0      AzureRM.Automation                  {Get-AzureRMAutomationHybridWorkerGroup, Get-AzureRmAutoma...
Manifest   2.5.0      AzureRM.Backup                      {Backup-AzureRmBackupItem, Enable-AzureRmBackupContainerRe...
Manifest   2.5.0      AzureRM.Batch                       {Remove-AzureRmBatchAccount, Get-AzureRmBatchAccount, Get-...
Manifest   2.5.0      AzureRM.Cdn                         {Get-AzureRmCdnProfile, Get-AzureRmCdnProfileSsoUrl, New-A...
Manifest   0.4.3      AzureRM.CognitiveServices           {Get-AzureRmCognitiveServicesAccount, Get-AzureRmCognitive...
Manifest   2.5.0      AzureRM.Compute                     {Remove-AzureRmAvailabilitySet, Get-AzureRmAvailabilitySet...
Manifest   2.5.0      AzureRM.DataFactories               {Remove-AzureRmDataFactory, Get-AzureRmDataFactoryRun, Get...
Manifest   2.5.0      AzureRM.DataLakeAnalytics           {Get-AzureRmDataLakeAnalyticsDataSource, New-AzureRmDataLa...
Manifest   3.3.0      AzureRM.DataLakeStore               {Get-AzureRmDataLakeStoreTrustedIdProvider, Remove-AzureRm...
Manifest   2.5.0      AzureRM.DevTestLabs                 {Get-AzureRmDtlAllowedVMSizesPolicy, Get-AzureRmDtlAutoShu...
Manifest   2.5.0      AzureRM.Dns                         {Get-AzureRmDnsRecordSet, New-AzureRmDnsRecordConfig, Remo...
Manifest   0.0.2      AzureRM.EventHub                    {New-AzureRmEventHubKey, Get-AzureRmEventHubNamespace, Get...
Manifest   2.5.0      AzureRM.HDInsight                   {Get-AzureRmHDInsightJob, New-AzureRmHDInsightSqoopJobDefi...
Manifest   2.5.0      AzureRM.Insights                    {Get-AzureRmUsage, Get-AzureRmMetricDefinition, Get-AzureR...
Manifest   1.1.0      AzureRM.IotHub                      {Add-AzureRmIotHubKey, Get-AzureRmIotHubEventHubConsumerGr...
Manifest   2.5.0      AzureRM.KeyVault                    {Add-AzureKeyVaultCertificate, Set-AzureKeyVaultCertificat...
Manifest   2.5.0      AzureRM.LogicApp                    {Get-AzureRmIntegrationAccountAgreement, Get-AzureRmIntegr...
Manifest   0.11.3     AzureRM.MachineLearning             {Move-AzureRmMlCommitmentAssociation, Get-AzureRmMlCommitm...
Manifest   0.3.3      AzureRM.Media                       {Sync-AzureRmMediaServiceStorageKeys, Set-AzureRmMediaServ...
Manifest   3.4.0      AzureRM.Network                     {Add-AzureRmApplicationGatewayAuthenticationCertificate, G...
Manifest   2.5.0      AzureRM.NotificationHubs            {Get-AzureRmNotificationHub, Get-AzureRmNotificationHubAut...
Manifest   2.5.0      AzureRM.OperationalInsights         {New-AzureRmOperationalInsightsAzureActivityLogDataSource,...
Manifest   2.5.0      AzureRM.PowerBIEmbedded             {Remove-AzureRmPowerBIWorkspaceCollection, Get-AzureRmPowe...
Manifest   2.5.0      AzureRM.Profile                     {Disable-AzureRmDataCollection, Enable-AzureRmDataCollecti...
Manifest   2.5.0      AzureRM.RecoveryServices            {Get-AzureRmRecoveryServicesBackupProperties, Get-AzureRmR...
Manifest   2.5.0      AzureRM.RecoveryServices.Backup     {Backup-AzureRmRecoveryServicesBackupItem, Get-AzureRmReco...
Manifest   2.5.0      AzureRM.RedisCache                  {Remove-AzureRmRedisCachePatchSchedule, New-AzureRmRedisCa...
Manifest   3.5.0      AzureRM.Resources                   {Get-AzureRmProviderOperation, Remove-AzureRmRoleAssignmen...
Manifest   0.11.3     AzureRM.Scheduler                   {Disable-AzureRmSchedulerJobCollection, Enable-AzureRmSche...
Manifest   2.5.0      AzureRM.ServerManagement            {Invoke-AzureRmServerManagementPowerShellCommand, Get-Azur...
Manifest   0.0        AzureRM.ServiceBus
Manifest   3.4.0      AzureRM.SiteRecovery                {Get-AzureRmSiteRecoveryFabric, New-AzureRmSiteRecoveryFab...
Manifest   2.5.0      AzureRM.Sql                         {Get-AzureRmSqlDatabaseTransparentDataEncryption, Get-Azur...
Manifest   2.5.0      AzureRM.Storage                     {Get-AzureRmStorageAccount, Get-AzureRmStorageAccountKey, ...
Manifest   2.5.0      AzureRM.StreamAnalytics             {Get-AzureRmStreamAnalyticsFunction, Get-AzureRmStreamAnal...
Manifest   2.5.0      AzureRM.Tags                        {Remove-AzureRmTag, Get-AzureRmTag, New-AzureRmTag}
Manifest   2.5.0      AzureRM.TrafficManager              {Disable-AzureRmTrafficManagerEndpoint, Enable-AzureRmTraf...
Manifest   2.5.0      AzureRM.UsageAggregates             Get-UsageAggregates
Manifest   2.5.0      AzureRM.Websites                    {Get-AzureRmAppServicePlan, Set-AzureRmAppServicePlan, New...
 
 
    Directory: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement
 
 
ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.4.0      Azure                               {Get-AzureAutomationCertificate, Get-AzureAutomationConnec...
 
 
    Directory: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\Storage
 
 
ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   2.5.0      Azure.Storage                       {Get-AzureStorageTable, New-AzureStorageTableSASToken, New...

Commands to Start With

# To log in to Azure Resource Manager
Login-AzureRmAccount
 
# To view all subscriptions for your account
Get-AzureRmSubscription
 
# View your current Azure PowerShell session context
# This session state is only applicable to the current session and will not affect other sessions
Get-AzureRmContext
 
# To select the default storage context for your current session
Set-AzureRmCurrentStorageAccount -ResourceGroupName "your resource group" -StorageAccountName "your storage account name"
 
# View your current Azure PowerShell session context
# Note: the CurrentStorageAccount is now set in your session context
Get-AzureRmContext
 
# To list all of the blobs in all of your containers in all of your accounts
Get-AzureRmStorageAccount | Get-AzureStorageContainer | Get-AzureStorageBlob

Examples

Get-AzureRmSubscription

PS C:\> get-azurermsubscription -subscriptionname "Visual studio enterprise"
 
 
SubscriptionName : Visual Studio Enterprise
SubscriptionId   : xxxxxxxx-yyyy-zzzz-wwww-aaaaaaaaaaaa
TenantId         : wwwwwwww-2222-dddd-4444-jjjjjjjjjjjjjj
State            : Enabled

Get-AzureRmVM

PS C:\> get-azurermvm
WARNING: Breaking change notice: In upcoming release, top level properties, DataDiskNames and NetworkInterfaceIDs, will be removed from VM object because they are also in
StorageProfile and NetworkProfile, respectively.
 
ResourceGroupName         Name   Location      VmSize  OsType          NIC ProvisioningState
-----------------         ----   --------      ------  ------          --- -----------------
AZURERESOURCEGROUP01 AzureDC01 westeurope Standard_A1 Windows azuredc01772         Succeeded
 
PS C:\> get-azurermvm -name azuredc01
 
cmdlet Get-AzureRmVM at command pipeline position 1
Supply values for the following parameters:
ResourceGroupName: azureresourcegroup01
WARNING: Breaking change notice: In upcoming release, top level properties, DataDiskNames and NetworkInterfaceIDs, will be removed from VM object because they are also in
StorageProfile and NetworkProfile, respectively.
 
 
ResourceGroupName   : azureresourcegroup01
Id                  : /subscriptions/be1b3ee6-4a03-4ba4-8ac0-75d5a451a364/resourceGroups/azureresourcegroup01/providers/Microsoft.Compute/virtualMachines/AzureDC01
VmId                : 8e334dc5-96c9-4a82-adc8-772a12976550
Name                : AzureDC01
Type                : Microsoft.Compute/virtualMachines
Location            : westeurope
Tags                : {}
HardwareProfile     : {VmSize}
NetworkProfile      : {NetworkInterfaces}
OSProfile           : {ComputerName, AdminUsername, WindowsConfiguration, Secrets}
ProvisioningState   : Succeeded
StorageProfile      : {ImageReference, OsDisk, DataDisks}
DataDiskNames       : {AzureDC01-20170201-155949}
NetworkInterfaceIDs : {/subscriptions/be1b3ee6-4a03-4ba4-8ac0-75d5a451a364/resourceGroups/AzureResourceGroup01/providers/Microsoft.Network/networkInterfaces/azuredc01772}

Resources

azurepowershell.txt · Last modified: 2021/09/24 00:24 by 127.0.0.1