Book a Demo

Author Topic: Powershell automation  (Read 11991 times)

aldrich

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Powershell automation
« on: November 03, 2015, 09:51:29 am »
I have a set of master documents in my model.
I'd like to run this in batch, by running powershell which would run automation against EA via cmdlets.

Has anyone tried this, and has some example scripts I could lift?

If Powershell isn't the right way to do this, any idea on what is?

I'd think this kind of scripting via a command shell would be useful, but I can't see how to do it from the EA User documentation

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Powershell automation
« Reply #1 on: November 03, 2015, 10:27:27 am »
I did not run powershell but WSH (windows scripting host). And that did work. I have switched to compiled Perl (from ActiveState) later and so lost contact with that.

q.

smendonc

  • EA User
  • **
  • Posts: 148
  • Karma: +5/-0
  • I love YaBB 1 Gold!
    • View Profile
Re: Powershell automation
« Reply #2 on: November 03, 2015, 12:02:58 pm »
You should be able to load 'Interop.EA.dll' into PowerShell which will give you access to all the scripting and other programmability features.  The documented api can then be used as the reference.  The most common 'issue' you will run into is that even a batch job needs to have interactive session, but it can be scheduled

Stan.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Powershell automation
« Reply #3 on: November 03, 2015, 12:52:48 pm »
Quote
You should be able to load 'Interop.EA.dll' into PowerShell which will give you access to all the scripting and other programmability features.  The documented api can then be used as the reference.  The most common 'issue' you will run into is that even a batch job needs to have interactive session, but it can be scheduled

Stan.
Hi Stan,

Do you have a, small, worked example you can share?

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

smendonc

  • EA User
  • **
  • Posts: 148
  • Karma: +5/-0
  • I love YaBB 1 Gold!
    • View Profile
Re: Powershell automation
« Reply #4 on: November 03, 2015, 04:44:16 pm »
Example below, It prints a pdf of the Test Environment Model package  from EAExample.

PowerShell has been updated since I last used it (v1.0) so com objects can be called directly - makes it a lot easier then loading the dll.

-------------------------------------------------
# Create the EA object
$ea = New-Object -ComObject "EA.Repository" -Strict

$ea.OpenFile("<path to example model>\EAExample.eap")

$pkg = "{407CEBA1-C9DB-47dd-B8BA-AD5D8ED6DC79}"
$template = "Model Report"
$report = "<path to report location>\Test Environment Model.pdf"

$project = $ea.GetProjectInterface()
$project.RunReport($pkg, $template, $report)


$ea.CloseFile()
$ea.Exit()

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Powershell automation
« Reply #5 on: November 03, 2015, 05:39:54 pm »
Cool!  Thanks Stan!

The script threw an exception:
Exception calling "RunReport" with "3" argument(s): "The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"

Not sure why?

Changing the RunReport to a GetFileNameDialog call (with appropriate arguments), "worked like a bought one"!

Paolo
« Last Edit: November 04, 2015, 11:07:24 am by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

smendonc

  • EA User
  • **
  • Posts: 148
  • Karma: +5/-0
  • I love YaBB 1 Gold!
    • View Profile
Re: Powershell automation
« Reply #6 on: November 04, 2015, 04:01:47 am »
On the off chance you spot something, I used the below to test run the script.  The EAExample.eap file was in a folder under 'My Documents' not the default location.

OS: Windows 10 Enterprise
EA: Version 12.0.1215
PowerShell Version:
Major  Minor  Build  Revision
-----    -----   -----   --------
5         0       10240 16384

aldrich

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Powershell automation
« Reply #7 on: December 12, 2015, 09:46:33 am »
Thanks all, I was able to get this to work like a charm.
Does anyone know how to execute a script externally from EA?

That is, I have a number of validation scripts within EA that I run prior to publication. It is tedious to run them by hand; I'd like to batch them in a powershell script (i.e. something like Repository.ExecuteScript(pathToScript one after another).

I was hoping there was a scripts collection off of the Repository interface, but no such luck. Any thoughts?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Powershell automation
« Reply #8 on: December 12, 2015, 04:28:49 pm »
You can, but it's not that easy.

Check the code for EA-Matic on GitHub This add-in executes scripts in EA.

Geert