Hey guys,
has anyone managed to execute Powershell scripts from NAV C/AL Code?
It's no problem to create a ps1 file and execute it with cmd.exe but I want to be able to access events and the output of the script, which cmd.exe is not offering. I tried some approaches with the DotNet System.Automation.Management.dll but it seems that at some point I always run into the error "Dynamic operations can only be performed in homogenous AppDomain". Has someone experienced this and found a solution?
Regards,
Mats
0
Comments
http://www.sist.biz/en/ [en] | http://www.sist.biz [de]
EDIT:
I think I found a solution. If you change <NetFx40_LegacySecurityPolicy enabled="true"/> to false it works. Not sure what this parameter is controlling though, is it safe to turn it off?
Also can't get events to work but at least I get the output now.
Did you find sample code somewhere using System.Management.Automation.dll in C/AL code? I'm trying to do the same thing (execute a powershell script from within C/AL) and I'm not having luck. I can execute it from the cmd.exe but I would like to stay away from that.
Thanks!!
I just want to add the information that I found.
You change/Remove the <NetFx40_LegacySecurityPolicy enabled="true"/> in the file: C:\Program Files\Microsoft Dynamics NAV\71\Service\Microsoft.Dynamics.Nav.Server.exe.config
Then restart the Dynamics NAV server.
Here is a code example to run powershell scripts from Visual Studio. I made .net plugin of this but haven't experimented with it yet. So far I at least get the output.
Edit: This won't work for NAV powershell cmdlets since they require admin rights.
Have you checked the cables?
Have you released the filters?
http://www.navfreak.com
Is there any security risk when
NetFx40_LegacySecurityPolicy enabled="true
is removed or changed to false in Microsoft.Dynamics.Nav.Client.exe.config?
Is it safe in terms of performance and security etc.? What are the disadvantages associated with this change?
Linkedin Profile: http://in.linkedin.com/in/dhanrajbansal
Note though, a possible issue has been reported recently when using this setting with value false: Depending on value of this switch and .net framework version, string comparison might yield different results in specific circumstances.
To be exact: Reserved Quantity field (table 32, ILE) might show incorrect value (0), due to string interpretation of flowfield condition (Source ID = '', Source Batch Name = ''). This issue is being addressed.