Time to look at the Get and Set Commandlets introduced with Cumulative Update 9 for Microsoft Dynamics NAV 2013 R2
These 2 new commandlets can be used to get and set the Object Properties from in objects exported to text files from Dynamics NAV 2013 and higher.
Let’s look at them in detail.
Get-NAVApplicationObjectFile
The Syntax:
Get-NAVApplicationObjectProperty [-Source] <String> [-Confirm] [-WhatIf] [<CommonParameters>]
-Source: | The <String> after the Source points to the source file from which you are reading the NAV Object file you want to split into multiple Object files
An example could be C:\temp\AllObjects.txt |
-Confirm | If set you will get a prompt before the command is run. |
-WhatIf | Interesting one. If set this shows you what would happen if the cmdlet was run, but it is actually not running it. |
-CommonParameters | The CommonParameters are things that are not specific to this cmdlet.
A great resource for the CommonParameters can be found here: |
Example:
Get-NAVApplicationObjectProperty -SourceC:\temp\NA2013R2CU9\COD2.TXT
This will give you an output of the Object Properties of the file or files identified. In itself this is not too interesting unless you can use it for something, but more about that in a later blog post.
Alternative you can also here use the “*” to filter your input.
Get-NAVApplicationObjectProperty -SourceC:\temp\NA2013R2CU9\COD*.TXT
In this case the output will be all of the Object properties of the Codeunits in the folder.
The commandlet also works on a text file with multiple objects as seen in the commandlet here:
Get-NAVApplicationObjectProperty -Source C:\temp\AllObjects.TXT
Set-NAVApplicationObjectFile
The Syntax:
Set-NAVApplicationObjectProperty [-Target] <String> [-DateTimeProperty <String>] [-ModifiedProperty <SetModifiedPropertyAction>] [-PassThru] [-VersionListProperty <String>] [-Confirm] [-WhatIf] [<CommonParameters>]
-Target: | The <String> after the Destination points to the folder where we want the individual object files written to.
An example could be: c:\temp\Destination\ |
-DateTimeProperty: | The <String> after the DateTimeProperty identifies the values the Date and Time should be set to in the object properties. |
-ModifiedProperty | The <SetModifiedPropertyAction> after the ModifiedProperty identifies the value you would like the Modified property to be set to. Only “Yes” or “No” is allowed. |
-PassThru | The PassThru is another SwitchParameter that instructs the command to return file info for all the files created. Default it will only return a list of files if this SwitchParameter is not set.
The file info includes information such as Mode, Date, Time, Length (File Size in Bytes). |
-VersionListProperty | The <String> after VersionListProperty is used to update the Object properties identified by the Target. |
-Confirm | If set you will get a prompt before the command is run. |
-WhatIf | Interesting one. If set this shows you what would happen if the cmdlet was run, but it is actually not running it. |
-CommonParameters | The CommonParameters are things that are not specific to this cmdlet.
A great resource for the CommonParameters can be found here: |
Examples:
Set-NAVApplicationObjectProperty -TargetC:\temp\NA2013R2CU9\COD1.TXT -VersionListProperty “MyVertical1.1”-ModifiedProperty No -DateTimeProperty (Get-Date -Year 2017 -Month 1 -Day 1 -Hour 0 -Minute 0 -Format g)
This will set the set the VersionList to MyVertical1.1, Clear the modified flag and set the date to January 1st, 2017 at midnight. You can write dates in many ways, but this one is pretty safe no matter what your regional setting might be in regards to Date and Time.
Many using source code control of some kind clear the object properties before putting the code in to the source control system including myself. Here is an example of how you can clear your object properties from one or more objects.
Set-NAVApplicationObjectProperty -TargetC:\temp\NA2013R2CU9\COD2.TXT -VersionListProperty “” -ModifiedProperty No -DateTimeProperty (”)
This commandlet will clear all Object Properties in the objects identified by the Target. (A special thanks to Bas Graaf for the clue to clearing the DateTimeProperty).