我正在使用以下代码从 Outlook 中检索特定的通讯录:
$outlook = $(New-Object -ComObject Outlook.Application)
$Session = $outlook.Session
$Session.Logon()
$ab = $Session.AddressLists | ? {$_.Name -eq 'test'}
然后尝试使用 C#$ab
使用以下命令将对象转换为 .net:
$source = @"
using Microsoft.Office.Interop.Outlook;
public unsafe static class OAB
{
public static void List(object Stream)
{
var i = Stream as Microsoft.Office.Interop.Outlook.AddressList;
return i;
}
}
"@
$cp = new-object System.CodeDom.Compiler.CompilerParameters
$cp.CompilerOptions = "/unsafe"
$cp.ReferencedAssemblies.Add('C:\wkdir\refassem\Microsoft.Office.Interop.Outlook.dll')
Add-Type -TypeDefinition $source -CompilerParameters $cp
我收到的错误是:
Since 'OAB.List(object)' returns void, a return keyword must not be followed by an object expression
免责声明,我是 C# 的新手,所以请放轻松!