We have a need to copy an entire AF database from our Production environment to our Test environment for testing new AF. We can't use the PI Connector because we want EVERYTHING copied, and PI Connector only does a few things. Historically I've used AFExport.exe and AFImport.exe.
But I am trying to automate the whole thing in PowerShell and saw Export-AFXml and Import-AFXml. The documentation on these is non existent as far as I can tell. Does anyone know if it's possible to export an entire AF database (library and elements) using these PowerShell commands? And if so, what is the syntax?
I'm open to other options I can write into a PowerShell script, I just like to stay native PowerShell if possible.
I think I actually got the export side down with this line:
$ExportFolder = D:
$AFServer = Get-AFServer -Name "AFServer01"
$AFDatabaseName = "Wind Farm"
$AFDatabase = Get-AFDatabase -Name $AFDatabaseName -AFServer $AFServer
$StartTime = ConvertFrom-AFRelativeTime *-1mo
$EndTime = ConvertFrom-AFRelativeTime *
Export-AFXml -ExportMode AllReferences,DefaultValues -StartTime $StartTime -EndTime $EndTime -File $ExportFolder\$AFDatabaseName.xml -AFObject $AFDatabase
The xml file created is exactly the same size as when I export it manually in System Explorer.
The problem I'm facing now is on import. Right now I'm using this:
$AFServer = Get-AFServer -Name "Server02"
$AFDatabaseName = "Wind Farm Test"
Add-AFDatabase -Name $AFDatabaseName -AFServer $AFServer | Out-Null
Import-AFXml -File $ImportFile -ImportMode AllowCreate,AutoCheckIn,PreserveUniqueIDs -AFObject (Get-AFDatabase -Name $AFDatabaseName -AFServer $AFServer -Refresh)
It's got a couple pitfalls that either aren't possible to get around or I'm missing.
- In this script, I have to create a new AF database first before I can import into it. In AFImport.exe, I was able to take an xml and import it directly into a server as a new database by any name I wanted. Can I do that with Import-AFXml?
- AFImport.exe has an option called "ContinueOnError". You would think if you export one database and import it somewhere else, there couldn't possible be errors. But that's not the case. And with AFImport.exe, if it comes across an error, it stops importing. In my case, it failed because somehow the source database (PI System Directory) had 2 elements next to each other with the same name. Do you know if there is a way to "ContinueOnError" for Import-AFXml?