How to specify custom COM enum as PowerShell method parameter How to specify custom COM enum as PowerShell method parameter powershell powershell

How to specify custom COM enum as PowerShell method parameter


We ended up using a compiled C# interop wrapper around the COM object. I was able to specify an int as the parameter and just used a case statement to pass the correct value from the enum. As far as I can tell there isn't a way to do this directly from Powershell and requires wrapping the COM object in managed code.

We have opened a dialog with Globalscape and hopefully this will be something they address in a future release.


We can try to fool the com object by creating the enum on your own and pass it to the function:

If you can upgrade to Powershell 5 try (in Powershell - enum is a new keyword in ver 5):

Enum SFTPAdvBool{        abFalse = 0        abTrue = 1        abInherited = -2}

And call:

$obj.SetHomeDir([SFTPAdvBool]::abTrue)

for anything older than PS 5 you can try:

$code = @"namespace SFTPCOMINTERFACELib {    public enum SFTPAdvBool {        abFalse = 0,        abTrue = 1,        abInherited = -2    }}"@Add-Type -TypeDefinition $code -Language CSharpVersion3

And call:

$obj.SetHomeDir([SFTPCOMINTERFACELib.SFTPAdvBool]::abTrue)

This will basically create a C# enum and will add it as a type into Powershell.


PowerShell v2.0 is archaic at this point, but it shouldn't be stopping you here. SFTPAdvBool appears to be from the GlobalScape EFT Server COM API, so that's what I'm assuming.

The issue is that you need a value of type SFTPAdvBool, according to the C# scripting examples (See ConfigureUser.cs for one use). For a .Net object, you'd define that as [SFTPAdvBool]::abTrue or [SFTPCOMINTERFACELib.SFTPAdvBool]::abTrue, but I'm not sure if that will work. I've not worked with COM enums in PowerShell before. You might need New-Object -ComObject SFTPCOMINTERFACELib.SFTPAdvBool or some variant.

If nothing works, you could use VBScript, or C#, or contact GlobalScape in the hopes they join the 21st century and drop COM, or use WinSCP's .Net library... but I'm betting you can't since you're working someplace that paid for EFT Server.