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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 23.06.2015, 11:00   #1  
Blog bot is offline
Blog bot
Участник
 
25,640 / 848 (80) +++++++
Регистрация: 28.10.2006
Windows PowerShell is very well suited for monitoring services because tasks can be repeated and they can run remotely. In this post we will look at how to check the Application Log via Windows PowerShell, locally as well as remotely, to look for errors or for certain words in the log. The customer story this time is that users report a problem and you need to find the cause. The first place to look (at least in some cases): the Application Log.

In future posts we will look at tracing the service tier/client activity using powershell and WCF, and other ways to monitor and troubleshoot. As always, comments are welcome if there are any particular things you would like to see.


Coffee Break 14 - Using Windows PowerShell to check and search the Application Log.
There are two main ways to get the Application Log with PowerShell:
  • Get-EventLog
  • Get-WinEvent
For more details on this (and which one to use), check this post on the Goatee PFE blog. In short: Get-EventLog is the simple way. Get-WinEvent is the more flexible way. Here, we will use Get-WinEvent.


Get the Application Log
Get-WinEvent -LogName Application -MaxEvents 100

or read it from a saved log:

Get-WinEvent -Path "c:TempMySavedLog.evtx" -MaxEvents100

or from a remote machine:

Get-WinEvent -MaxEvents 100 -ComputerName MySvr2012

or from a list of remote machines:

$Servers="localhost","MySvr2012"

foreach($Server in $Servers) {$Server ;Get-WinEvent -logname Application -MaxEvents 100 -ComputerName $Server}



Look for providers

One of the advantages of Get-WinEvent, is that it filters on source, and only transfers the filtered events back when retrieving events from a remote machine. In the Application Log, Provider = Source. When we are just looking for Dynamics NAV events, then filter on Dynamics NAV. First find the provider / source:

Get-WinEvent -ListProvider *nav* | Format-Table

Then filter on Dynamics NAV, whether the service you want to check is NAS, Web Service, Dynamics NAV Server, or any other service. For this example let's use "MicrosoftDynamicsNavServer$DynamicsNAV80"

Get-WinEvent -ProviderName "MicrosoftDynamicsNavServer`$DynamicsNAV80"

Notice the escape character ` before the $-sign to tell PowerShell that we want the $-sign, and are not referring to a variable.


Use FitlerHashTable for filters
Once we start adding multiple filters to Get-WinEvent, we need to provide them as Key-Value pairs. The supported values for filtering is listed here: Supported Filter Values:
  • LogName <String>
  • ProviderName <String>
  • Path <String>
  • Keywords <Long>
  • ID <Int32>
  • Level <Int32>
  • StartTime <DateTime>
  • EndTime <DataTime>
  • UserID <SID>
  • Data <String>
  • * <String>
The syntax is:
@{Key=Value;Key=Value;etc}

Example: Look for Application Log entries from Dynamics NAV:

Get-WinEvent -FilterHashtable @{LogName = "Application"; ProviderName = "MicrosoftDynamicsNavServer`$DynamicsNAV80"}



Useful filters:

Find error logs: Filter on Level = 2 (Level 4 is Information)

Date Filters: $MyDate = Get-Date / (Get-Date).AddDays(-2)

Example: Find Error logs from Dynamics NAV for the last week:

$EndDate=Get-Date

$BeginDate= (Get-Date).AddDays(-7)

Get-WinEvent -FilterHashtable @{LogName = "Application"; ProviderName = "MicrosoftDynamicsNavServer`$DynamicsNAV80" ; StartTime = $BeginDate; EndTime = $EndDate ; Level =2}


And Remotely
Invoke-Command -ComputerName MySvr2012 -ScriptBlock {Get-WinEvent -FilterHashtable @{LogName = "Application" ; ProviderName = "MicrosoftDynamicsNavServer`$DynamicsNAV80" ; level = 2}}

More details about remoting PowerShell with Dynamics NAV here.


Find specific events
Find a specific event in the Application Log:

$pattern = "NAS Startup Parameter"#or

$pattern = "The service has registered service principal names "#or

$pattern = "Deadlock"#or

$pattern = "System.InvalidCastException"#or

$pattern = "Server instance: DynamicsNAV80"#or

$pattern = "listening to requests at net.tcp"#... etc

Get-WinEvent -FilterHashtable @{LogName = "Application" ; ProviderName = "MicrosoftDynamicsNavServer`$DynamicsNAV80"} | where {$_.Message.Contains($pattern)} | foreach {"$($_.Message) `n-------`n"}


Printing details
You may have noticed that the examples above only print the first few characters of each event. To get the full event (but also mess up your screen), simply format as list:

Get-WinEvent -FilterHashtable @{LogName = "Application" ; ProviderName = "MicrosoftDynamicsNavServer`$DynamicsNAV80"} | Format-List

or keep it in table format but wrap each line:

Get-WinEvent -FilterHashtable @{LogName = "Application" ; ProviderName = "MicrosoftDynamicsNavServer`$DynamicsNAV80"} | Format-Table -AutoSize -Wrap

or control the output via a variable:

$Events= Get-WinEvent -FilterHashtable @{LogName = "Application" ; ProviderName = "MicrosoftDynamicsNavServer`$DynamicsNAV80"}

$Events[1].Message







Jasminka Thunes, Escalation Engineer Dynamics NAV EMEA

Lars Lohndorf-Larsen, Escalation Engineer Dynamics NAV EMEA

Bas Graaf, Senior Software Engineer Dynamics NAV







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

Опции темы Поиск в этой теме
Поиск в этой теме:

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

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

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

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