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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 19.02.2015, 17:00   #1  
Blog bot is offline
Blog bot
Участник
 
25,644 / 848 (80) +++++++
Регистрация: 28.10.2006
The | (pipe) functionality in Windows PowerShell offers endless opportunities for formatting and manipulating results from one cmdlet to the next.


Coffee Break 4: Piping in Windows PowerShell
Each time we run a Windows PowerShell cmdlet, the resulting output is not text but an Object providing structured information of the result.

Example: Get-NAVServerInstance will return existing instances of NAVServerInstance Objects:



with the following properties:
  • ServerInstance
  • DisplayName
  • State
  • ServiceAccount
  • Version
  • Default
Windows PowerShell can pipe objects. Pipelines are a series of cmdlets (segments) separated by a Pipeline character ‘|’. Each Item is passed through all segments of the pipeline (left to right) before the next is processed.

Piping example:

First import your Dynamics NAV cmdlets (if you are not already in the Microsoft Dynamics NAV Administration Shell, that is):

Import-Module 'C:Program FilesMicrosoft Dynamics NAV80ServiceMicrosoft.Dynamics.Nav.Management.dll'

This imports the NAV.Management.dll for version 80 (=NAV 2015). Adjust the path to the version you are working with.

Get-NAVServerInstance

In case Get-NAVServerInstance returns more than one, then let's filter the one(s) that we want by piping the original result through a filter. Or said in other words: We pipe it to the Where-Object cmdlet:

#Filter by version

Get-NAVServerInstance | where-Object –Property Version -like "8.0*”

One can also omit the –Property parameter here, and just run:

Get-NAVServerInstance | where-Object Version -like "8.0*”



Then we will take the result and pipe that to another cmdlet, let's pipe it to Sync-NAVTenant:

Get-NAVServerInstance | where-Object –Property Version -like "8.0*” | Sync-NAVTenant

Note also that the syntax of Where-Object cmdlet has changed across Windows PowerShell versions, so for compatibility, and going forward , the following syntax should be used:

Get-NAVServerInstance | where-Object {$_.Version -like "8.0*”} | Sync-NAVTenant

Where $_ is used to reference the Item returned by the previous pipeline segment (in the above example, it references the instance of NavServerInstance Object returned by Get-NAVServerInstance cmdlet). However running the above will still fail to sync Microsoft Dynamics NAV tenants for instances that are not running (State: stopped). This will not abort the process, but we can also further filter on only those instances that are running:

Get-NAVServerInstance | where-Object {$_.Version -like "8.0*”} | where-Object {$_.State –eq 'Running'} | Sync-NAVTenant

The two pipline segments filtering the output can of course be combined in one. We join the filtering conditions using –And operator. Note that Logical operators (-And / -Or) are valid only within script blocks.

Get-NAVServerInstance | where-Object {$_.Version -like "8.0*” -And $_.State –eq 'Running'} | Sync-NAVTenant



See further content about Piping here: https://technet.microsoft.com/en-us/.../dd347655.aspx



Jasminka Thunes, Escalation Engineer Dynamics NAV EMEA

Lars Lohndorf-Larsen, Escalation Engineer Dynamics NAV EMEA

[img]//feeds.feedburner.com/~r/MicrosoftDynamicsNavTeamBlog/~4/AWx92-ShZFk[/img]

Источник: http://feedproxy.google.com/~r/Micro...ak-piping.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 


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

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

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