AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 27.06.2016, 16:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,617 / 848 (80) +++++++
Регистрация: 28.10.2006
kurthatlevik: How I saved thousands of dollars on my Azure environments!
Источник: https://kurthatlevik.wordpress.com/2...-environments/
==============

I just love such headlines, because it instantly attracts attention.



But in this case it is actually true. And Microsoft is even wants us to do this. I want to write how to automatically shut down and start up environments in Azure, so that you are not spending more than needed. This post is for newbies, and experts surely will bombard the comment section with improved suggestions on how to make it even better.

In this example I have 4 environment running in Azure and the machine type I prefer is the D13_v2. This will cost me 3696 USD per month if I just let them stay on for 744 hours per month.



But I only plan to use them 07:00 à 17:00 Monday to Friday. This is 200 hours per month, and then it will just cost 993 USD J A lot of fun can be done with these extra credits.



So what is the next step? The trick is to use the Azure Powershell Runbook. Here is the step-by-step instruction on how to set it up:

1. Log into Azure, and open the Azure automation



2. Add an Automation Account.
    Create a name, like “TurnOffOnVM”.
    Select the subscription, and if a resource group should be created. Also if you want an Azure Run As Account. (I didn’t bother to have that, since I have no important stuff on these environments)



3. Then create an Asset named “automation” for holding credentials, that will run the shutdown/start up scripts. The credentials you are using must have the rights to run scripts and to start/stop VM’s.


4. Let’s create 2 Runbooks, that holds the scripts and schedules for the start and stop scripts.



5. Use the “Powershell Workflow” type



 

6. Let’s put in the “Start script”. It’s done here



 

I have removed my VM-names in this example.



If you wonder what your VM name is, it is the computer name, that can be seen here:


Here is a copy-paste version of the Start-up script:

workflow StartVM


{


    $cred = get-automationpscredential -name “automation”


    add-azureaccount -credential $cred


    select-azuresubscription -subscriptionname “Microsoft Azure Enterprise”


 

    $VMs = Get-AzureVM


 

foreach($VM in $VMs)


{


if ($VM.Name -In “VMName1”, “VMName2”, “VMName3”, “VMName4” )


{


if ($VM.PowerState -ne “Started”)


        {


     Start-AzureVM -Name $VM.Name -ServiceName $VM.ServiceName -ErrorAction Continue


        }


}


}


}


7. Let’s put in the “Stop script”. It is basically the same procedure as creating the “start script”, so I just add the copy-past version of the script.

workflow StopVM


{


    $cred = get-automationpscredential -name “automation”


    add-azureaccount -credential $cred


    select-azuresubscription -subscriptionname “Microsoft Azure Enterprise”


 

    $VMs = Get-AzureVM


 

    foreach($VM in $VMs)


    {


    if ($VM.Name -In “VMName1”, “VMName2”, “VMName3”, “VMName4” )


    {


        if($vm.Status -eq ‘ReadyRole’)


        {


        Stop-AzureVm -Name $vm.Name -ServiceName $vm.ServiceName -Force


        }


 

    }


    }


}


 

Remember to press the “publish” button the scripts J

8. Let’s create a schedule (one for the Start runbook, and one for the stop runbook)






9. You can now monitor the start/stop scripts:



 

10. Go party with all the credits you have saved! And if you see me, and use this script, buy me a beer J

 

Happy DAX’ing J




Источник: https://kurthatlevik.wordpress.com/2...-environments/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Старый 28.06.2016, 00:14   #2  
lvan is offline
lvan
Участник
Аватар для lvan
Лучший по профессии 2014
 
858 / 82 (4) ++++
Регистрация: 15.04.2011
Записей в блоге: 1
еще есть один был трик - создать машину D а потом поменять на A
она не будет мигрировать на новое железо, и по факту останется на D, но платить будешь как за A
правда проверял давно, может уже и не работает.
За это сообщение автора поблагодарили: Logger (1).
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
kurthatlevik: New Dynamics AX On premise = Azure Stack Blog bot DAX Blogs 0 31.03.2016 17:11
kurthatlevik: New Microsoft Dynamics AX – A guide for using retail sales prices and discounts Blog bot DAX Blogs 0 01.12.2015 18:12
kurthatlevik: How to evaluate Dynamics AX ISV solutions Blog bot DAX Blogs 0 28.10.2015 20:11
kurthatlevik: How to evaluate Dynamics AX ISV solutions Blog bot DAX Blogs 0 01.10.2015 21:11
axsa: How to transform an automated business process into an intelligent business process using Dynamics and Azure ML Blog bot DAX Blogs 1 29.10.2014 15:10

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 19:36.