You must specify a codeunit and a Business Central Server instance.
Optionally, you can specify other parameters.
By default, the OnRun trigger is called, but you can specify a different method name and pass it an optional string argument.
You can run the codeunit within the scope of a company, a tenant, or both.
Optionally, you can specify the language that you want to use when you invoke the codeunit.
Return values are ignored.
Examples
EXAMPLE 1
Invoke-NAVCodeunit -ServerInstance BC -CompanyName 'CRONUS International Ltd.' -CodeunitId 100000 -Language 'da-DK'
This example invokes codeunit 100000 and calls the OnRun trigger because no other method is specified.
The code runs with Danish language settings in the CRONUS International Ltd.
company in the Business Central Server instance BC.
EXAMPLE 2
Invoke-NAVCodeunit -ServerInstance BC -Tenant Tenant1 -CompanyName MyCompanyName -CodeunitId 2
The example invokes codeunit 2, which initializes the MyCompanyName company.
The example runs the UpgradeStep2 method in codeunit 104048, which is part of the Upgrade Toolkit for Business Central.
Parameters
-Argument
Specifies a string argument that is passed to the specified method on the codeunit.
Parameter properties
Type:
String
Default value:
None
Supports wildcards:
False
DontShow:
False
Parameter sets
(All)
Position:
Named
Mandatory:
False
Value from pipeline:
False
Value from pipeline by property name:
True
Value from remaining arguments:
False
-CodeunitId
Specifies the ID of the codeunit that you want to invoke. The Invoke-NAVCodeunit cmdlet calls the OnRun trigger in the specified codeunit. You can call another method if you specify it in the MethodName parameter.
Parameter properties
Type:
Int32
Default value:
None
Supports wildcards:
False
DontShow:
False
Parameter sets
(All)
Position:
Named
Mandatory:
True
Value from pipeline:
False
Value from pipeline by property name:
True
Value from remaining arguments:
False
-CompanyName
Specifies the name of the company that you want to run the codeunit in. If you do not set this parameter, the codeunit will run in the default company for the Business Central Server instance.
Parameter properties
Type:
String
Default value:
None
Supports wildcards:
False
DontShow:
False
Parameter sets
(All)
Position:
Named
Mandatory:
False
Value from pipeline:
False
Value from pipeline by property name:
True
Value from remaining arguments:
False
-Confirm
Prompts you for confirmation before running the cmdlet.
Parameter properties
Type:
SwitchParameter
Default value:
None
Supports wildcards:
False
DontShow:
False
Aliases:
cf
Parameter sets
(All)
Position:
Named
Mandatory:
False
Value from pipeline:
False
Value from pipeline by property name:
False
Value from remaining arguments:
False
-DelayBetweenRetries
Specifies the delay between retries.
Parameter properties
Type:
TimeSpan
Default value:
None
Supports wildcards:
False
DontShow:
False
Parameter sets
(All)
Position:
Named
Mandatory:
False
Value from pipeline:
False
Value from pipeline by property name:
False
Value from remaining arguments:
False
-Force
Forces the command to run without asking for user confirmation.
Parameter properties
Type:
SwitchParameter
Default value:
None
Supports wildcards:
False
DontShow:
False
Parameter sets
(All)
Position:
Named
Mandatory:
False
Value from pipeline:
False
Value from pipeline by property name:
False
Value from remaining arguments:
False
-Language
Specifies the language that the codeunit will run in. You must specify a valid culture name for a language in Business Central, such as en-US or da-DK. If the specified language does not exist on the Business Central Server instance, the codeunit will run in en-US.
Parameter properties
Type:
LanguageSetting
Default value:
None
Supports wildcards:
False
DontShow:
False
Parameter sets
(All)
Position:
Named
Mandatory:
False
Value from pipeline:
False
Value from pipeline by property name:
True
Value from remaining arguments:
False
-MaxRetries
Specifies the maximum number of retries for the operation in case of failure.
Parameter properties
Type:
Int32
Default value:
None
Supports wildcards:
False
DontShow:
False
Parameter sets
(All)
Position:
Named
Mandatory:
False
Value from pipeline:
False
Value from pipeline by property name:
False
Value from remaining arguments:
False
-MethodName
Specifies the method that will be called. If no method is specified, the OnRun trigger is called.
Parameter properties
Type:
String
Default value:
None
Supports wildcards:
False
DontShow:
False
Parameter sets
(All)
Position:
Named
Mandatory:
False
Value from pipeline:
False
Value from pipeline by property name:
True
Value from remaining arguments:
False
-NetworkTimeout
Specifies the network timeout of the operation.
Parameter properties
Type:
TimeSpan
Default value:
None
Supports wildcards:
False
DontShow:
False
Parameter sets
(All)
Position:
Named
Mandatory:
False
Value from pipeline:
False
Value from pipeline by property name:
False
Value from remaining arguments:
False
-ProgressAction
A common PowerShell parameter that determines how PowerShell responds to progress updates generated by a script, cmdlet, or provider. Learn more.
Parameter properties
Type:
ActionPreference
Default value:
None
Supports wildcards:
False
DontShow:
False
Aliases:
proga
Parameter sets
(All)
Position:
Named
Mandatory:
False
Value from pipeline:
False
Value from pipeline by property name:
False
Value from remaining arguments:
False
-RetryMode
Specifies the retry mode when the service instance is not available.
Possible values: Fixed, Exponential
Parameter properties
Type:
RetryMode
Default value:
None
Accepted values:
Fixed, Exponential
Supports wildcards:
False
DontShow:
False
Parameter sets
(All)
Position:
Named
Mandatory:
False
Value from pipeline:
False
Value from pipeline by property name:
False
Value from remaining arguments:
False
-ServerInstance
Specifies the name of a Business Central Server instance, for example, BC or myinstance. You can specify either the full name of an instance, such as MicrosoftDynamicsNavServer$myinstance or the short name such as myinstance.
Parameter properties
Type:
String
Default value:
None
Supports wildcards:
False
DontShow:
False
Parameter sets
(All)
Position:
0
Mandatory:
True
Value from pipeline:
True
Value from pipeline by property name:
True
Value from remaining arguments:
False
-Tenant
Specifies the ID of the tenant that you want to invoke the codeunit in, such as Tenant1.
This parameter is required unless the specified service instance is not configured to run multiple tenants.
Parameter properties
Type:
TenantId
Default value:
None
Supports wildcards:
False
DontShow:
False
Aliases:
Id
Parameter sets
(All)
Position:
Named
Mandatory:
False
Value from pipeline:
False
Value from pipeline by property name:
True
Value from remaining arguments:
False
-TimeZone
Specifies the time zone that the invoked codeunit will use for date calculations.
You can set the parameter to the following values:
Utc - Uses Universal Coordinated Time (UTC) as the time zone.
This is the default value. If you do not set this parameter, then UTC is used.
ClientTimezone - Uses the time zone that is configured for the computer on which the cmdlet is run.
TenantTimezone - Uses the default time zone that is configured for the tenant.
The tenant's time zone is configured when the tenant is mounted on the Business Central Server instance. This is only relevant when the Business Central Server instance is configured as a multitenant instance.
ServicesDefaultTimeZone - Uses the default time zone that is configured web services on the Business Central Server instance.
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Parameter properties
Type:
SwitchParameter
Default value:
None
Supports wildcards:
False
DontShow:
False
Aliases:
wi
Parameter sets
(All)
Position:
Named
Mandatory:
False
Value from pipeline:
False
Value from pipeline by property name:
False
Value from remaining arguments:
False
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable,
-ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see
about_CommonParameters.
Feedback
Was this page helpful?
No
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?