Microsoft Azure のWindows仮想マシンで、PowerShellを使ったAzureサービスの管理を行う際の、PowerShellセットアップ手順です。
PowerShell を使って Azure操作ができるようにする為の第一歩となります。
1.PowerShell のダウンロード
まず、WindowsにインストールするPowerShell をダウンロードします。
Downloads ページから、 PowerShellの「Windows install」をクリックします。(以下の赤枠の箇所をクリック)
すると、exeファイル(WindowsAzurePowershellGet.3f.3f.3fnew.exe)がダウンロードされます。
ダウンロードしたexeファイルを実行すると、「Web Platform Installer」が起動します。「インストール」ボタンをクリックします。
以下のように、インストールが進みます。
Microsoft Azure PowerShell のインストールが完了した際には、以下の画面が表示されるため、「完了」ボタンをクリックします。
以下のような画面が表示されますが、今回必要なのは「Microsoft Azure PowerShell」だけなので、「終了」ボタンをクリックします。
インストールが完了すると、「コントロールパネル」-「プログラム」-「プログラムと機能」で、Microsoft Azure PowerShell がインストールされたことが確認できます。
2.PowerShell で「Azure」モジュールをインポート
Windows Power Shell を起動します。
Windows Azure Power Shell モジュールを確認してみるため、「Get-Module」コマンドを実行してみます。
PS C:\Users\testuser> Get-Module -ListAvailable
多くの出力がされますが、Nameで「Azure」が表示される事を確認できます。
次は、「Azure」モジュールをPowerShellでインポートします。
PS C:\Users\testuser> Import-Module Azure PS C:\Users\testuser>
以上でモジュール側の準備が完了した為、次はAzure Subscription情報をインポートします。
3.Azure Subscription情報をインポート
まず、PowerShell から 「Get-AzurePublishSettingsFile」コマンドを実行します。
PS C:\Users\testuser> Get-AzurePublishSettingsFile
すると、ブラウザが起動し、認証フォームが表示されます。
Azureの認証を行うと、以下の画面が表示され、拡張子「.publishsettings」ファイルをダウンロードできます。
ファイル名は、「従量課金制-2-9-2016-credentials.publishsettings」のような形式となります。
次にダウンロードしたファイルを「Import-AzurePublishSettingsFile」コマンドでインポートします。
PS C:\Users\testuser> Import-AzurePublishSettingsFile "C:\Users\testuser\Downloads\従量課金制-2-9-2016-credentials.publishsettings" Id : (xxxxxxxxx) Name : 従量課金制 Environment : AzureCloud Account : (xxxxxxxxx) State : Properties : {[Default, True]} PS C:\Users\testuser>
以上で、インポートが完了しました。
PowerShell で、Azure の管理ができるようになります。
4.Azure用のコマンドを試してみる
インポートした Azure Subscription を確認してみます。なお、ユーザー固有の情報は伏字にしています。
PS C:\Users\testuser> Get-AzureSubscription SubscriptionId : (xxxxxxxxx) SubscriptionName : 従量課金制 Environment : AzureCloud DefaultAccount : (xxxxxxxxx) IsDefault : True IsCurrent : True TenantId : CurrentStorageAccountName : PS C:\Users\testuser>
仮想マシン情報を表示してみます。
PS C:\Users\testuser> Get-AzureVM ServiceName Name Status ----------- ---- ------ fanbright test01 StoppedDeallocated fanbright test02 StoppedDeallocated fanbright test03 StoppedDeallocated fanbright-win fanbright-win ReadyRole PS C:\Users\testuser>
データベース情報を確認してみます。まずは、サーバーを確認してみます。
PS C:\Users\testuser> Get-AzureSQLDatabaseServer ServerName Location AdministratorLogin Version ---------- -------- ------------------ ------- k8fxxxxxxx Japan West sqluser 12.0 PS C:\Users\testuser>
サーバー名とデータベース名を指定して確認する事ができますので、サーバー上に複数のデータベースがある場合に、確認したいデータベースだけを指定する事もできます。
PS C:\Users\testuser> Get-AzureSqlDatabase -ServerName "k8fxxxxxxx" -DatabaseName "FBRDB" Name : FBRDB CollationName : SQL_Latin1_General_CP1_CI_AS Edition : Standard MaxSizeGB : 250 MaxSizeBytes : 268435456000 ServiceObjectiveName : S0 ServiceObjectiveAssignmentStateDescription : Complete CreationDate : 2016/02/09 12:51:14 RecoveryPeriodStartDate : 2016/02/09 13:01:57 PS C:\Users\testuser>