web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Powershell execution from dynamics ax 2012

(0) ShareShare
ReportReport
Posted on by 5,994

Hi Guys,

I am need of some help related to powershell execetion from dynamics ax. i have created a powershell script that is runing perfect fine. i am now calling that script from dynamics ax using .net classes. i am facing any error when the powershell window get open and it tries to execute the powershell script in it.

File C:\test\test.ps1 cannot be loaded because the execution of scripts is disabled 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

i google it, and i found it is something related to execution policy and scope which is currently as restricted on my windows 2008 server and scope is undefined.

My question here is that how i can modify my script to add some logic or script that enable powershell script execution in unrestricted mode and i do not get this error.

i am pasting my simple powershell script also

Set-ExecutionPolicy –Scope Process Unrestricted
$filelocation = dir c:\
$filename = "Archive.zip"
$shell_app=new-object -com shell.application
$zip_file= $shell_app.namespace("c:\$filename")
$destination=$shell_app.namespace("c:\")
$destination.copyhere($zip_file.items())

I apreciate any help here. 

 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,884 Most Valuable Professional on at

    This is a security measurement disallow you to run unsigned scripts.
    You have two options:

    1. Change the execution policy to be more benevolent (e.g. Set-ExecutionPolicy RemoteSigned). But you can't do it from your script, if it's not allowed to run!
    2. Sign your script.

    Although changing the execution policy is perfectly fine in development environments, I would rather sign the script if it is to be used in a production. It's safer and it actually simplifies configuration of test and production environments.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans