Hello
I have a business requirement to be able to submit / check-in a new document into a M-Files vault via PowerShell. Pretty simple task (single doc, few properties to set).
What is my best approach ?
Any pointer / advice most appreciated.
Your best strategy would be to use the REST API from PowerShell if you want to do everything in PowerShell script: logging on to a vault, creating an object, settings properties and uploading a file.
I have been trying to use the M-Files COM API from PowerShell (Windows PowerShell 5.1), and API calls. Logging in into a vault and using methods like $vault.ObjectFileOperations.FindFilesByChecksumWithNumericalDigests(...) can be easily done in PowerShell script, but setting up some COM objects that need to be used in other API methods is a PITA and I haven't found any way to do it in PowerShell (for example setting up search conditions). PowerShell will throw an error like "Cannot convert the "System.__ComObject" ... to "Object" which has to do how PowerShell lazy binds COM objects.
Should you really need to use the M-Files COM API, then program the functionality in a c# .NET full framework 4.x DLL and call this from PowerShell. You can easily add DLLs into the PowerShell runtime with Add-Type cmdlet and use the DLL classes from PowerShell.
Your best strategy would be to use the REST API from PowerShell if you want to do everything in PowerShell script: logging on to a vault, creating an object, settings properties and uploading a file.
I have been trying to use the M-Files COM API from PowerShell (Windows PowerShell 5.1), and API calls. Logging in into a vault and using methods like $vault.ObjectFileOperations.FindFilesByChecksumWithNumericalDigests(...) can be easily done in PowerShell script, but setting up some COM objects that need to be used in other API methods is a PITA and I haven't found any way to do it in PowerShell (for example setting up search conditions). PowerShell will throw an error like "Cannot convert the "System.__ComObject" ... to "Object" which has to do how PowerShell lazy binds COM objects.
Should you really need to use the M-Files COM API, then program the functionality in a c# .NET full framework 4.x DLL and call this from PowerShell. You can easily add DLLs into the PowerShell runtime with Add-Type cmdlet and use the DLL classes from PowerShell.
That is a possibility as well, but you would need some plumbing to start the exit, wait for it to exit, handle exit code, output and error channel.
Consider encapsulating the functionality into a .NET DLL instead of an EXE and injecting it into the PowerShell runtime/.NET Appdomain using "Add-Type", like this: