functions/set-d365workstationmode.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

<#
    .SYNOPSIS
        Set the Workstation mode
         
    .DESCRIPTION
        Set the Workstation mode to enabled or not
         
        It is used to enable the tool to run on a personal machine and still be able to call Invoke-D365TableBrowser and Invoke-D365SysRunnerClass
         
    .PARAMETER Enabled
        $True enables the workstation mode while $false deactivated the workstation mode
         
    .EXAMPLE
        PS C:\> Set-D365WorkstationMode -Enabled $true
         
        This will enable the Workstation mode.
        You will have to restart the powershell session when you switch around.
         
    .NOTES
        Author: Mötz Jensen (@Splaxi)
         
        You will have to run the Initialize-D365Config cmdlet first, before this will be capable of working.
         
#>

function Set-D365WorkstationMode {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [boolean] $Enabled
    )

    Set-PSFConfig -FullName "d365fo.tools.workstation.mode" -Value $Enabled
    Get-PSFConfig -FullName "d365fo.tools.workstation.mode" | Register-PSFConfig

    Write-PSFMessage -Level Host -Message "Please <c='em'>restart</c> the powershell session / console. This change affects core functionality that <c='em'>requires</c> the module to be <c='em'>reloaded</c>."
}