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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 24.05.2010, 15:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
saveenr: Dynamics AX 2009: Integrating AX with Powershell
Источник: http://blogs.msdn.com/saveenr/archiv...owershell.aspx
==============

[UPDATE on 2010-05-15]

To documentation for this powershell module has been placed here: http://cid-19ec39cb500669d8.skydrive...owershell.docx

 

if you read this blog, you know I love command line interfaces – so this shouldn’t be a surprise. If you look at the Dynamics AX BI CodePlex project, you’ll see a Visual Studio 2008 project called “DynamicsAXPS”.



 

This is a Powershell 2.0 module that lets you start exploring and controlling AX from the command line. In this post I’ll demonstrate how to use it.

First, install Powershell 2.0 and start it. This module assumes you already have the AX Client installed on the machine and configured to connect to an AX Server.

LOADING THE MODULE

Once you build the project you’ll see these DLLs in the bin/debug directory… The module itself is the file called “DynamicsAXPS.dll”


Now load it via this command
Import-Module .\DynamicsAXPS.dll



The warnings are because I have some non-standard cmdlet verbs defined.



FINDING AX CMDLETS
Get-Command -Module DynamicsAXPS



INTERROGATING THE AOT

Let’s get a node in the AOT – I’ll choose the CustTable
$custtable = Get-AXNode "\Data Dictionary\Tables\CustTable"
$custtable | Get-Member




Of course we can pipe this to Out-GridView …

 
$custtable = Get-AXNode "\Data Dictionary\Tables\CustTable"
$custtable | Get-Member | Out-GridView






What about the child nodes under CustTable? Use Get-AXNodeChildItem
Get-AXNodeChildItem "\Data Dictionary\Tables\CustTable"



What if we wanted all the nodes underneath CustTable recursively? Just add the –Recurse flag. As you can see there are a lot of nodes

 

Get-AXNodeChildItem "\Data Dictionary\Tables\CustTable" -Recurse


Use Get-AXNodeProperties to get info about the properties for a specific node.
Get-AXNodeProperties "\Data Dictionary\Tables\CustTable"



LABELS

If you need to get the value for a label us Get-AXLabel
Get-AXLabel SYS11307



You can ask for multiple labels at the same time
Get-AXLabel SYS11307,SYS125115

 

Getting MetaData for Tables, Enums, and EDTs

There are three commands available.

One for Extended Data Types.
Get-AXEDTMetaData ABCModelType



One for Enums:
Get-AXEnumMetaData ABCModel



One for Tables
Get-AXTableMetaData CustTable



If you are curious about the metadata, you can retrieve it from the metadata objects that are returns

Here’s how to find out about the fields.
$md = Get-AXTableMetaData CustTable
$md.Fields | Out-GridView




OK, that’s a lot of fields, we can filter it down

 
$md = Get-AXTableMetaData CustTable
$md.Fields | select Name,DataType,FieldType,DisplayLength  | Out-GridView




 

GETTING DATA FROM A TABLE
$datatable = Get-AXTableData -Table CustTable -Fields *
$datatable.Rows | Out-GridView






 
$datatable = Get-AXTableData -Table CustTable -Fields AccountNum,Name,Phone
$datatable.Rows | Out-GridView




 

CREATE A TABLE VIA AN XPO
Create-XPOForTable -Name Foo -Filename "D:\\Create_Table_Foo.xpo" -Fields A,B,C –FieldTypes INT,STRING,REAL

This creates a simple XPO file that will create that table.

Just import the XPO like any other and your table is ready




ADD RECORDS TO A TABLE
Add-AXRecord -Table Foo -Fields A,B,C  -Values (1,"FOO",3.3)
Add-AXRecord -Table Foo -Fields A,B,C  -Values (2,"Bar",7.1)


And if you open the table in AX …


You’ll see the data has been placed in the table
 



Источник: http://blogs.msdn.com/saveenr/archiv...owershell.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Теги
powershell, полезное

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
emeadaxsupport: List of fixes that improve performance of certain features in Dynamics AX 2009 Blog bot DAX Blogs 0 13.10.2009 19:06
gatesasbait: Dynamics AX 2009 SSRS and SSAS Integration Tips Blog bot DAX Blogs 3 09.07.2009 13:07
Dynamics AX: Managing Your Supply Chain Using Microsoft Dynamics AX 2009 - Book Review Blog bot DAX Blogs 0 31.03.2009 23:06
JOPX: Dynamics AX 2009 - Enterprise Portal link bonanza Blog bot DAX Blogs 0 27.11.2008 01:05
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05

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

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

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