Had a requirement to unzip files from AX for one of our interfaces. I didn't want to install any third party software on our server as the security policy prevents it.
Tried using Microsoft.Deployment Framework within AX (http://www.eggheadcafe.com/software/aspnet/34793683/titel-zip-with-zipwriter-microsoftdynamicsframeworkdeployment.aspx), but ran into issues using the framework to unzip files.
Solution
Since, our AOS Servers run on Windows Server 2008 and Powershell is something which comes default with this edition of windows, I thought why not leverage it as it has a powerful scripting engine and I can see it as a predecessor to VB Scripting.
Following code snippet, is the powershell script which I wrote to unzip the files.
And, here is the X++ code which calls the script
Tried using Microsoft.Deployment Framework within AX (http://www.eggheadcafe.com/software/aspnet/34793683/titel-zip-with-zipwriter-microsoftdynamicsframeworkdeployment.aspx), but ran into issues using the framework to unzip files.
Solution
Since, our AOS Servers run on Windows Server 2008 and Powershell is something which comes default with this edition of windows, I thought why not leverage it as it has a powerful scripting engine and I can see it as a predecessor to VB Scripting.
Following code snippet, is the powershell script which I wrote to unzip the files.
And, here is the X++ code which calls the script
I remembered my Unix scripting and vi editor days when working on Powershell editor.
Also, this is a very useful reference if you are graduating from VBScript to Powershell
Some other useful links on Powershell from Axaptapedia and Brandon's blog
Happy Powershelling with DAx!
3 comments:
Will this work with in a Batch Job?
Hi Dilip,
Thanks for nice post, i am using the example in one of my code but unfortunatly i am getting an error,
File C:\test\test.ps1 cannot be loaded because the execution of scripts is disa
bled on this system. Please see "get-help about_signing" for more details.
At line:1 char:17
+ c:\test\test.ps1 <<<<
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
The error is because powershell window open from AX does not allow execution of script due to undefined scope and restricted execution policy.
do u know how i can change the executionPolicy and scope so powershell window can run the scripts.
i appreciate the response.
Hi Dilip,
Thanks for nice post, i am using the example in one of my code but unfortunatly i am getting an error,
File C:\test\test.ps1 cannot be loaded because the execution of scripts is disa
bled on this system. Please see "get-help about_signing" for more details.
At line:1 char:17
+ c:\test\test.ps1 <<<<
+ CategoryInfo : NotSpecified: (:) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
The error is because powershell window open from AX does not allow execution of script due to undefined scope and restricted execution policy.
do u know how i can change the executionPolicy and scope so powershell window can run the scripts.
i appreciate the response.
Post a Comment