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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 28.01.2018, 22:12   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
yetanotherdynamicsaxblog: PowerShell script for synchronizing the database
Источник: http://yetanotherdynamicsaxblog.blog...hronizing.html
==============

In this post I want to share a neat way to use a PowerShell script for running the database synchronization when working. You probably already know you can run the database synchronization from within Visual Studio, and that is probably where most developers and consultants will do this operation, but sometimes you want the option to just run a script. Examples of this is when you copy a database between environments, or during upgrade operations.

Let's put the script out, and I'll discuss the parts below.

#Requires -RunAsAdministrator
Import-Module "$PSScriptRoot\AOSEnvironmentUtilities.psm1" -DisableNameChecking
Import-Module "$PSScriptRoot\CommonRollbackUtilities.psm1" -DisableNameChecking

function Run-DBSync()
{
$SyncToolExecutable = '{0}\bin\Microsoft.Dynamics.AX.Deployment.Setup.exe' -f $(Get-AosWebSitePhysicalPath)
$params = @(
'-bindir', $(Get-AOSPackageDirectory)
'-metadatadir' , $(Get-AOSPackageDirectory)
'-sqluser', $(Get-DataAccessSqlUsr)
'-sqlserver', $(Get-DataAccessDbServer)
'-sqldatabase', $(Get-DataAccessDatabase)
'-setupmode', 'sync'
'-syncmode', 'fullall'
'-isazuresql', 'false'
'-sqlpwd', $(Get-DataAccessSqlPwd)
)
& $SyncToolExecutable $params 2>&1 | Out-String
}

Run-DBSync

Let's look at what this script does. The very first line is just a hint to the runtime that this script must be run in elevated mode. The reason is that it must get some information from the system that requires admin rights. Typically I also stop some services, like the Management Reporter Process Service, before I run the synchronization, and obviously a non-admin will struggle to do that.

Notice that I have imported some modules, and you may be wondering where I got those. These PowerShell modules are part of the Software Deployable Packages, and either you can create one yourself, or simply download one of those made available by Microsoft in LCS. Extract the package and look under the following path, \AOSService\Scripts. Just grab the two files and make sure you save them alongside your script, like the example below:



The rest is simply building the parameters for the synchronization operation, and running the tool that does the job. The output is sent to the host, so if you want to look at the result you may want to run this script in PowerShell ISE (Admin mode).

What is also neat, is that it will pick up the database credentials used for your environment, so you don't have to put those details in the script yourself.

In any case, it is a neat study in how you can organize your script in such a way that you get the code all in one visible column. It's also a stepping stone to start building your own set of scripts to maintain your development environments.

Finally, a small disclaimer: Microsoft may very well change how their PowerShell modules work in the future, so if that happens, the script above will have to change.




Источник: http://yetanotherdynamicsaxblog.blog...hronizing.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Kine’s info: Copy Microsoft Dynamics NAV company by SQL script into another database v2 Blog bot NAV: Blogs 0 15.05.2016 17:11
Kine’s info: Copy Microsoft Dynamics NAV company by SQL script into another database Blog bot NAV: Blogs 0 15.05.2016 17:11
Kine: Copy Microsoft Dynamics NAV company by SQL script into another database Blog bot Dynamics CRM: Blogs 0 18.10.2013 10:07
PowerShell Script to Run As A Different User Blog bot DAX Blogs 0 01.08.2013 00:12
Microsoft Dynamics NAV Database Archive for all Country Versions Blog bot Dynamics CRM: Blogs 0 11.03.2011 18:43
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

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

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

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 06:57.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.