Question

I'm having a problem with using C# in my PowerShell script. The library I'm trying to use is InterIMAP

Specifically, I am trying to convert this constructor:

using InterIMAP;

IMAPConfig config = new IMAPConfig("server","username","password", true, false, "INBOX");

The PowerShell script I have so far:

$loadLib =[Reflection.Assembly]::LoadFile('C:\Users\......\InterIMAP.dll);

$config= [InterIMAP.IMAP.IMAPConfig]::IMAPConfig("imap.gmail.com", $user, $password, $true, $true, "INBOX");

I think the issue I'm having is because the IMAP class has a pointer to the IMAPConfig class: http://interimap.codeplex.com/SourceControl/latest#InterIMAP/InterIMAP/Client/IMAP.cs

I must be doing something wrong. Any help appreciated

Was it helpful?

Solution

In your PowerShell code, you're accessing IMAPConfig() as a static method of the IMAPConfig class, which I'm guessing is not valid. In order to use an object constructor in PowerShell, you need to use the New-Object cmdlet.

The -TypeName parameter specifies the .NET class that you want to instantiate. The -ArgumentList parameter accepts an array of arbitrary System.Object objects that represent the constructor parameters.

$config = New-Object -TypeName InterIMAP.IMAP.IMAPConfig -ArgumentList @('imap.gmail.com', $User, $Password, $true, $true, 'INBOX');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top