Hello, I hope that I'm right here.
I wrote a powershell script in Version 2 for controlling the CAD system Catia v5.
I updated to Powershell 5 and the script didn't work anymore.
It's still okay, if I use the "-Version 2" parameter.
How long is this option supported?
Thank you for your help.
Kind regards
Kevin
Not related to PowerShell core. To answer your question, this is supported so fat till 2019, its possible where ever version 2.0 is enabled and -version is an option available for powerRhell.exe which is already done with the development, hence this option will be there till powershell.exe dies :-)
Yeah, this isn't available to PowerShell core, and isn't even guaranteed in any version of windows PowerShell.
Many security-conscious folks widely uninstall PowerShell V2 from every machine it's still available on, which breaks this option.
I would recommend simply updating your script. :slightly_smiling_face:
Thank you both for your help.
@vexx32 the problem appears in the following lines:
$catia=new-object -com catia.application
$catia.documents.open($CatiaFile)
Powershell seems to have problems finding the 'open'-routine:
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $catia.documents.open("C:\temp\test.CATPart")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Opening documents in Office works this way, so I guess that Catia is the problem...
Mmm you'll need to look back a bit farther. It can't find the method, because the .documents property is empty. Might want to check the contents of $catia and check the properties it has available, as that might have differences in the way the COM object manifests between versions of PowerShell. 馃檪
@inno-kd Try powershell -mta instead. PowerShell 2's default runspace has an apartment state of MTA, later versions moved to STA since that's compatible with more things.
Mmm you'll need to look back a bit farther. It can't find the method, because the
.documentsproperty is empty. Might want to check the contents of$catiaand check the properties it has available, as that might have differences in the way the COM object manifests between versions of PowerShell.
@vexx32 Thank you for the hint. This is the content list of $catia:
$catia=new-object -com catia.application
$catia | gm
TypeName: System.__ComObject#{7d2c8116-dc44-0000-0280-030ba6000000}
Name MemberType Definition
---- ---------- ----------
BeginURConcatenation Method void BeginURConcatenation ()
CreateMail Method Mail CreateMail ()
CreateSendTo Method SendToService CreateSendTo ()
DisableNewUndoRedoTransaction Method void DisableNewUndoRedoTransaction ()
EnableNewUndoRedoTransaction Method void EnableNewUndoRedoTransaction ()
FileSelectionBox Method string FileSelectionBox (string, string, CatFileSelectionMode)
GetItem Method CATBaseDispatch GetItem (string)
GetWorkbenchId Method string GetWorkbenchId ()
Help Method void Help (string)
InputBox Method string InputBox (string, string, string, short, short, string, int)
MsgBox Method short MsgBox (string, short, string, string, int)
Quit Method void Quit ()
StartCommand Method void StartCommand (string)
StartWorkbench Method void StartWorkbench (string)
StopURConcatenation Method void StopURConcatenation (string)
ActiveDocument Property Document ActiveDocument () {get}
ActivePrinter Property Printer ActivePrinter () {get} {set}
ActiveWindow Property Window ActiveWindow () {get}
Application Property Application Application () {get}
Batch Property Batch Batch () {get} {set}
CacheSize Property int CacheSize () {get} {set}
Caption Property string Caption () {get} {set}
DisplayFileAlerts Property bool DisplayFileAlerts () {get} {set}
Documents Property Documents Documents () {get}
FileSearchOrder Property string FileSearchOrder () {get} {set}
FileSystem Property FileSystem FileSystem () {get}
FullName Property string FullName () {get}
Height Property float Height () {get} {set}
HSOSynchronized Property bool HSOSynchronized () {get} {set}
Interactive Property bool Interactive () {get} {set}
Left Property float Left () {get} {set}
LocalCache Property string LocalCache () {get} {set}
Name Property string Name () {get} {set}
Parent Property CATBaseDispatch Parent () {get}
Path Property string Path () {get}
Printers Property Printers Printers () {get}
RefreshDisplay Property bool RefreshDisplay () {get} {set}
SettingControllers Property SettingControllers SettingControllers () {get}
Settings Property Settings Settings () {get}
StatusBar Property string StatusBar () {get} {set}
SystemConfiguration Property SystemConfiguration SystemConfiguration () {get}
SystemService Property SystemService SystemService () {get}
Top Property float Top () {get} {set}
UndoRedoLock Property bool UndoRedoLock () {get} {set}
Visible Property bool Visible () {get} {set}
Width Property float Width () {get} {set}
Windows Property Windows Windows () {get}
@SeeminglyScience Thank you, too. I tried to start PS with the -mta parameter but it didnt work either.
Is there any other way to create the com-Object?
It might be a casing issue, then? Your original code is looking at $catia.documents, and the property here is listed with capital D not lowercase. In most cases it won't make a difference, but this may be one of the times it does. :slightly_smiling_face:
This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.