2
4

More than 5 years have passed since last update.

Windows に Azure PowerShell をインストールしてリソースグループを作成するところまで

Last updated at Posted at 2019-03-23

はじめに

Azure PowerShell を使い始める手順です。しばらく使っていないとすぐに忘れるので、備忘録として。
Azure CLI 版はこちら

インストール

PowerShell を開いて以下のコマンドを実行します。(以下のプロンプトが表示された場合は両方 YES を選択)

> Install-Module -Name Az -AllowClobber -Scope CurrentUser

NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet
 provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\cloudadmin\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by
running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install
and import the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

インストールが完了したら次のコマンドを実行してバージョンを確認します。

> Get-InstalledModule -Name Az | select Version,Name

Version Name
------- ----
1.5.0   Az

【参考】Azure PowerShell モジュールのインストール

ログイン

Execution Policy が Restricted に設定されていると Azure PowerShell モジュールのロードに失敗するため、Policy を RemoteSigned に変更します。

> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

以下のコマンドを実行すると Microsoft アカウントのサインイン画面が開くので、Azure 管理用のアカウントでサインインします。

Connect-AzAccount

ログインに成功すると現在のサブスクリプションが表示されます。

【参考】Azure PowerShell モジュールのインストール

サブスクリプション選択

次のコマンドで現在のサブスクリプションを確認します。

> Get-AzContext | select Name

次のコマンドを実行して、選択するサブスクリプションの SubscriptionId を確認します。

> Get-AzSubscription

次のコマンドを実行して、サブスクリプションを切り替えます。

> Get-AzSubscription -SubscriptionId <SubscriptionId> | Set-AzContext

再度次のコマンドを実行し、選択したサブスクリプションが表示されることを確認します。

> Get-AzContext | select Name

【参考】複数の Azure サブスクリプションの使用

リソースグループ作成

次のコマンドを実行してロケーションの一覧を確認します。

> Get-AzLocation | Format-Table

Location           DisplayName
--------           -----------
eastasia           East Asia
southeastasia      Southeast Asia
centralus          Central US
eastus             East US
eastus2            East US 2
westus             West US
northcentralus     North Central US
southcentralus     South Central US
northeurope        North Europe
westeurope         West Europe
japanwest          Japan West
japaneast          Japan East
brazilsouth        Brazil South
australiaeast      Australia East
australiasoutheast Australia Southeast
southindia         South India
centralindia       Central India
westindia          West India
canadacentral      Canada Central
canadaeast         Canada East
uksouth            UK South
ukwest             UK West
westcentralus      West Central US
westus2            West US 2
koreacentral       Korea Central
koreasouth         Korea South
francecentral      France Central
francesouth        France South
australiacentral   Australia Central
australiacentral2  Australia Central 2
southafricanorth   South Africa North
southafricawest    South Africa West

次のコマンドを実行してリソースグループを作成します。

> New-AzResourceGroup -Name <ResourceGroupName> -Location <LocationName>

次のコマンドを実行してリソースグループの一覧を確認します。

> Get-AzResourceGroup | Format-Table

【参考】New-AzResourceGroup

まとめ

リソースグループまでできたら、あとはよしなにリソース作っていきましょう。

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4