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

Announcements

No record found.

News and Announcements icon
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,165 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
    99,611 Super User 2026 Season 1 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
    99,611 Super User 2026 Season 1 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,065 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,132 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 703 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans