{"id":43480,"date":"2016-12-07T11:00:30","date_gmt":"2016-12-07T09:00:30","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/nav\/?p=13405"},"modified":"2024-03-05T11:33:59","modified_gmt":"2024-03-05T19:33:59","slug":"coffee-break-automate-it","status":"publish","type":"post","link":"https:\/\/www.microsoft.com\/en-us\/dynamics-365\/blog\/business-leader\/2016\/12\/07\/coffee-break-automate-it\/","title":{"rendered":"Coffee Break: Automate it!"},"content":{"rendered":"
The Coffee Break Team is back, and this time we will unite the best of the two worlds and show how we can utilize the power of Windows PowerShell, using your favorite application: Dynamics NAV. While we do recognize that scripting complex PowerShell tools and modules is not to everyone\u2019s taste, C\/AL is something we all do in Dynamics NAV world. So let\u2019s put them together and see how you can extend your application with PowerShell.<\/p>\n
This time, the user scenario can be to automate diagnostics of your Dynamics NAV system and shorten the time and effort it takes to collect all needed details. In this first post we will look at how to use PowerShell to collect some basic diagnostic details. The attached objects consist of a PowerShell runner codeunit, to invoke and manage PowerShell sessions, another codeunit to specify the diagnostics you chose to run, a log table you can export, and two pages to bind them all.<\/p>\n
The essence of invoking and running a PowerShell session is described in this blog post<\/a>, and involves the PowerShell Runner Add-In (deployed with the product). This time we will go a step further and show how to collect the resulting output. Once you run the cmdlet, the result, in fact a collection of them, is read using a PS object \u2018wrapper\u2019 (also part of the PowerShell Runner Add-In). In its most basic form, this would read in this result:<\/p>\n ReturnObject.GetProperty<\/em> enables you to then query for specific properties.<\/p>\nResultsEnumerator := PSRunner. Results.GetEnumerator;\n\nReturnObject := ReturnObject.PSObjectAdapter;\n\nReturnObject.PSObject := ResultsEnumerator.Current;<\/pre>\n