Skip to main content

Notifications

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

  • Suggested answer
    YUN ZHU Profile Picture
    84,274 Super User 2025 Season 1 on at
    RE: How to use Windows Powershell in Business Central onprem?

    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

  • Martin Ruhland Profile Picture
    5 on at
    RE: How to use Windows Powershell in Business Central onprem?

    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
    84,274 Super User 2025 Season 1 on at
    RE: How to use Windows Powershell in Business Central onprem?

    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

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: How to use Windows Powershell in Business Central onprem?

    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
    Amit Baru Profile Picture
    3,029 on at
    RE: How to use Windows Powershell in Business Central onprem?

    Hi,

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

    Regards

    Amit Sharma

    www.erpconsultors.com

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics

Product updates

Dynamics 365 release plans