Jerome Lefebvre

Exporting AF Objects using Powershell

Blog Post created by Jerome Lefebvre on Aug 29, 2018

A while back I wrote about exporting AF objects such as templates, UOMs, etc. using AF SDK.

Localizing the AF Example kits - Part 1 - Exporting a database


This time I wanted to discuss to show a small example to do the same thing using Powershell.


AF Allows very fine grained export of AF objects, for example you can manually export a template by right clicking on it and using the "Export To File..." option.


The same functionality is available via the export-AFXML commandlet in Powershell.


All you need to do is pass it an AFObject that you have. For example, you can grab all AF templates in a particular database as in the example below:


$af = Get-AFServer -Name $afName
$db = Get-AFDatabase -AFServer $af -Name $dbName

foreach ($template in $db.ElementTemplates) {
    $xml = Export-AFXml -AFObject $template


The $xml object is then a MemoryStream object and regular PowerShell methods can be used to store this object as a file.


You can look at the full sample code here:


GitHub - JeromeLefebvre/PowerShell---Export-and-Import-AF-Objects: A short example on how to use PowerShell to export an…