Tag: Business Central Administration

  • Removing Business Central Docker containers with PowerShell

    Removing Business Central Docker containers with PowerShell

    Yesterday I bumped into an intermittent issue on our Jenkins CI server where some Business Central containers where not getting removed after use. This led me to find a way of removing Business Central Docker containers with PowerShell, and a topic for a blog post. The issue seems to be with a process keeping the NavContainerHelper container folder open, which is stopping the script from removing it.. anyway, that’s not what this post is about.

    As a temporary work-around while I get to the root cause of the issue, I decided to build the containers with a unique name and setup a nightly cleanup job to remove any surplus containers on the build server.

    To do this, I first need a list of containers to remove. I used the docker ps command, formatting the result a a table to make it easier to use in PowerShell:

    $containers = docker ps -a --filter "name=bc*" --format "{{.Names}}"

    Filtering

    I was using the prefix “bc” on my container names, so I’ve selected this as my filter “name=bc*”. You could also filter on the image using the ancestor filter. For example:

    $containers = docker ps -a --filter "ancestor=mcr.microsoft.com/businesscentral/sandbox:gb-ltsc2019"

    Unfortunately I couldn’t get the ancestor filter to work with a more generic image name (i.e. mcr.microsoft.com/businesscentral/sandbox) which limited it’s usefulness in my scenario.

    There is also the label filter which is useful. The Business Central images come with a number of labels which we can retrieve by querying our containers. For example:

    PS C:\WINDOWS\system32> docker ps -a --format "{{.Labels}}"
    country=gb,tag=0.0.9.97,nav=,osversion=10.0.17763.914,platform=15.0.37865.39262,created=201912201932,cu=update31,eula=https://go.microsoft.com/fwlink/?linkid=86
    1843,legal=http://go.microsoft.com/fwlink/?LinkId=837447,maintainer=Dynamics SMB,version=15.1.37881.39313
    country=W1,legal=http://go.microsoft.com/fwlink/?LinkId=826604,maintainer=Dynamics SMB,nav=2018,tag=0.0.9.2,version=11.0.19394.0,created=201903101911,cu=rtm,eul
    a=https://go.microsoft.com/fwlink/?linkid=861843,osversion=10.0.17763.316
    cu=rtm,eula=https://go.microsoft.com/fwlink/?linkid=861843,legal=http://go.microsoft.com/fwlink/?LinkId=826604,maintainer=Dynamics SMB,nav=2018,country=gb,creat
    ed=201903102009,osversion=10.0.17763.316,tag=0.0.9.2,version=11.0.19394.0

    The above output shows a list of label key/value pairs being used by containers on my machine (I’ve only got Business Central and NAV containers). One label common to all my containers is “maintainer=Dynamics SMB”, which we could use in our filtering as follows:

    docker ps -a --filter "label=maintainer=Dynamics SMB"

    Formatting the output

    After running the script (with –format “{{.Names}}”), $containers will look something like this:

    bccontainer1
    bccontainer2
    bccontainer3

    I only want the container name so I’m only requesting this one field in the format parameter. If I wanted more information I could simply list out the additional fields required. For example:

    $containers = docker ps -a --format "{{.Names}} {{.ID}} {{.Image}}"

    With my list of container names I can now loop through and invoke the Remove-NavContainer Cmdlet on each name:

    $containers = docker ps -a --filter "name=c*" --format "table {{.Names}}"
    
    foreach ($container in $containers) {
        Write-Host 'Removing ' $container
        try {
          Remove-NavContainer -containerName $container
        }
        catch {
          Write-Host 'Could not remove ' $container -f Red
        }
    }

    As I still had problems with the NavContainerHelper folder being locked, the script was still failing on some containers (Jenkins restart required) so I added a try-catch to make sure the script at least attempts to remove all containers.

    That’s it, dirty hack temporary fix complete!

  • Add User in Dynamics 365 Business Central Cloud

    Business Central Cloud User

    In one of my earlier blog posts I wrote how you can add a user in Business Central On-premises (formerly Dynamics NAV) using PowerShell. This blog post shows how to add a user in Business Central Cloud / SaaS.

    The big difference between Business Central On-premises and Business Central Cloud (or SaaS) is that the Cloud version requires Azure Active Directory (AAD) authentication. As a consequence, to create a new user in Business Central Cloud you must first create a user in AAD and assign a Business Central licence to this user.

    There are a number of ways to create an AAD user, for instance via the Office 365 Administration Center or from the Azure Portal. In this post we’ll add the AAD user though the office.com admin center.

    Creating an AAD user through the Microsoft 365 Admin Center

    As an Office 365 administrator, open office.com and you’ll have access to the Admin Center:

    Office 365 Administration
    Office 365 Administration

    Note: If you can’t see the admin center icon above, try selecting ‘All apps’ and look through the list. If it’s still not there check your Microsoft 365 user permissions with an administrator.

    With the Microsoft 365 admin center open we can create a new user:

    Add Office 365 user

    Fill in the basic user information:

    Add Microsoft 365 userAfter selecting Next, assign the Business Central licence to the user (and any other licenses required):

    Assign user licences

    Optionally add additional user rights, then finish:

    Finish adding Microsoft 365 user

    With the Microsoft 365 user created, we can now add the user to Business Central.

    Add User in Dynamics 365 Business Central Cloud

    Once the user has an Azure Active Directory account with a Business Central licence assigned, we can add the user to Dynamics 365 Business Central Cloud via the Users page:

    Find the Users page via the search function (Alt+Q):

    Find Business Central Users page

    Open the Process menu:

    Business Central Add User

    Click Get New Users from Office 365:

    Get New Users from Office 365

    Business Central will now query active directory and add any new users it finds with a Business Central licence assigned.

    Add User in Dynamics 365 Business Central Cloud

    With the new Business Central user created, you can now continue the user setup by assigning User Groups and/or Permission Sets to the user record.