![](https://livestylewebsitestorage.blob.core.windows.net/livestylewebsitescontainer/2022/07/automatically-start-stop-azure-vm-after-business-hours_1_1-1024x689.png)
Windows Virtual Desktop の利用などにより、Azure 上でユーザーのクライアント端末を運用するケースは増えているかと思います。その際に気になるのが、業務時間外にも発生してしまうVM(Virtual Machine)のコストです。全く稼働がない状態で課金が発生してしまうことは大変もどかしい!もったいない!とお考えの方々に、Azure Automation をご紹介いたします。
Azure Automation とは
Azure Automation は Azure上で プロセスの自動化 / 構成の管理 / 更新の管理 などを行うための PowerShell や Python を実行できるサービスです。
利用方法
まずは、Azure Automation の一般的なスクリプトの実行についてご紹介いたします。
- Azure 上から以下の「Automation アカウント」を探します。
![](https://livestylewebsitestorage.blob.core.windows.net/livestylewebsitescontainer/2022/07/automatically-start-stop-azure-vm-after-business-hours_2-62cd4eb17fcee-1024x492.png)
2. 自動化には「Runbook」を利用します。「Runbook」 には予め、定期的に実行したいスクリプトを登録しておきます。
![](https://livestylewebsitestorage.blob.core.windows.net/livestylewebsitescontainer/2022/07/automatically-start-stop-azure-vm-after-business-hours_3.png)
3. PowerShell を選択した場合は、以下のように Azure のモジュール内に存在しているコマンドがいくつか用意されており、キャンパス(画面右のエディタ)に追加することですぐにテストが可能です。
![](https://livestylewebsitestorage.blob.core.windows.net/livestylewebsitescontainer/2022/07/automatically-start-stop-azure-vm-after-business-hours_4-62cd4ec4cd636-1024x287.png)
4. 定期的な実行を行うには、「スケジュール」から、実行のタイミングをスケジュールします。
![](https://livestylewebsitestorage.blob.core.windows.net/livestylewebsitescontainer/2022/07/automatically-start-stop-azure-vm-after-business-hours_5-62cd4ecea33fb-1024x499.png)
カレンダーをスケジュールするように実行のタイミングを決定します。営業時間外に毎日実行することも、1時間毎に実行することも可能です。
![](https://livestylewebsitestorage.blob.core.windows.net/livestylewebsitescontainer/2022/07/automatically-start-stop-azure-vm-after-business-hours_6.png)
5. Azure VMの開始・停止は、「Automation アカウント」の以下の関連リソースから設定を行います。
![](https://livestylewebsitestorage.blob.core.windows.net/livestylewebsitescontainer/2022/07/automatically-start-stop-azure-vm-after-business-hours_7-62cd4ede79a0f-1024x565.png)
「Target ResourceGroup Names」 に管理対象となるVMが含まれているリソースグループを指定します。なお、既定値の「*」はすべてのリソースグループのVMを対象としてしまうためご注意ください。
![](https://livestylewebsitestorage.blob.core.windows.net/livestylewebsitescontainer/2022/07/automatically-start-stop-azure-vm-after-business-hours_8.png)
6. あとはスケジュールを設定することでVMの自動起動、停止を簡単に管理することが可能です。
最後に
構成方法や料金体系についてご相談がありましたら、ぜひ Livestyle までお問い合わせください!