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 :
Small and medium business | Business Central, N...
Suggested Answer

How to use Windows Powershell in Business Central onprem?

(0) ShareShare
ReportReport
Posted on by 5

Hello everyone!

I'm trying to execute a Powershell script in Business Central.

Importing the necessary dll was easy, but everytime i try to run a simple script, it will throw an error ("Ambiguous Match found").

Is it possible to do this? If yes, what am i doing wrong?

This is my code so far:

dotnet
{
    assembly("System.Management.Automation")
    {
        type("System.Management.Automation.PowerShell"; "PowerShell") { }
    }
}

pageextension 50164 DotNetItem extends "Item List"
{
    trigger OnOpenPage()
    var
        Shelly: DotNet PowerShell;
    begin
        Shelly := Shelly.Create();
        Shelly.AddScript('C:\Users\MartinRuhland\Documents\Zeug\Testscript.ps1');
        Shelly.BeginInvoke();
    end;
}

Regards

Martin

I have the same question (0)
  • Suggested answer
    Amit Baru Profile Picture
    3,037 on at

    Hi,

    As per my understanding. Pls repair the Application from Setup.

    Regards

    Amit Sharma

    www.erpconsultors.com

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,105 Moderator on at

    Have you tried to debug this?

    And i believe that this will be executed on the BC middle tire server and not on the client. So did you place your powershell file on the server?

    I have never seen any example code doing this from AL. Hopefully someone else here may have an example for you.

  • Suggested answer
    YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at

    Hi, I see a similar approach in NAV, but I'm not sure if it still works in BC On-Pre, so hopefully the link below will give you some hints.

    https://cloudblogs.microsoft.com/dynamics365/no-audience/2015/12/21/coffee-break-use-the-powershell-runner-add-in/?source=nav

    Thanks.

    ZHU

  • Martin Ruhland Profile Picture
    5 on at

    Thanks for the replies! Unfortunately I'm still having the same issue. The Debugger isn't really helpful here.

    The NAV approach is interesting, but I don't know how to translate it into BC or if it's even possible.

    After i little more digging I found this: forum.mibuso.com/.../nav-2013r2-running-powershell-script-from-c-al-code

    Is there something like a LegacySecurityPolicy in BC?

  • Suggested answer
    YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at

    Hi, I checked Microsoft.Dynamics.Nav.Server.exe.config file, and did not find <NetFx40_LegacySecurityPolici enabled="true"/> line.

    pastedimage1663197543494v3.png

    Also I don't know if it matters, you can try the following settings.

    https://docs.microsoft.com/ja-jp/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6

    ·Get-ExecutionPolicy -List

    pastedimage1663197236670v1.png

    ·Set-ExecutionPolicy -ExecutionPolicy ByPass -Scope CurrentUser

    pastedimage1663197505516v2.png

    Hope this helps.

    Thanks.

    ZHU

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans