小编Nic*_*ula的帖子

无法加载Exchange PowerShell管理单元:"Microsoft.Exchange.Data.Directory.Globals"的类型初始值设定项引发异常

我有以下代码,用于在加载Exchange 2010快照时创建PowerShell运行空间.

Dim runspaceConfig = RunspaceConfiguration.Create()

Dim snapInException As PSSnapInException = Nothing
runspaceConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", snapInException)

Dim runspace = RunspaceFactory.CreateRunspace(runspaceConfig)
runspace.Open()
Run Code Online (Sandbox Code Playgroud)

自安装Visual Studio 2012后,我在执行将管理单元添加到runspace配置的行时开始出现以下错误.

System.Management.Automation.Runspaces.PSSnapInException occurred
  HResult=-2146233087
  Message=Cannot load Windows PowerShell snap-in Microsoft.Exchange.Management.PowerShell.E2010 because of the following error: The type initializer for 'Microsoft.Exchange.Data.Directory.Globals' threw an exception.
  Source=System.Management.Automation
  WasThrownFromThrowStatement=False
  StackTrace:
       at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadCustomPSSnapIn(PSSnapInInfo mshsnapinInfo)
       at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIn(PSSnapInInfo mshsnapinInfo)
       at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIn(PSSnapInInfo mshsnapinInfo, PSSnapInException& warning)
       at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.DoAddPSSnapIn(String name, PSSnapInException& warning)
       at System.Management.Automation.Runspaces.RunspaceConfiguration.AddPSSnapIn(String name, PSSnapInException& warning)
Run Code Online (Sandbox Code Playgroud)

我已经能够确认nlog在某种程度上导致了这个问题.在创建powershell运行空间之前创建nlog记录器的组合会导致错误.

如果我从我的应用程序配置中删除nlog配置部分并只创建一个空的nlog记录器,则加载管理单元时没有错误.此外,如果我将nlog配置保留在我的应用程序配置中但不创建nlog记录器,则该管理单元也会成功加载.

  • 我尝试在x64和x86中构建项目.
  • 我已经重新安装了交换管理工具.
  • 我已尝试在交换环境中的另一台机器上进行测试.

如果有人能提供任何可以帮我解决这个问题的建议,我会很高兴.

谢谢

.net powershell exchange-server nlog exchange-server-2010

12
推荐指数
1
解决办法
1万
查看次数

Import-PSSession:已为'%'命令跳过代理创建,因为PowerShell无法验证其名称是否安全

我有一个Sharepoint服务器场设置,我正在使用远程PowerShell从域中的Windows 7计算机连接到我的一个应用程序/搜索服务器.客户端和应用程序服务器都具有PowerShell 2,执行策略设置为不受限制且启用了psremoting.此外,我正在运行cmdlet作为域管理员帐户.

我可以使用以下cmdlet创建到远程服务器的会话:

$Session = New-PSSession -ConfigurationName "Microsoft.PowerShell" -ConnectionUri "http://app01-spl1:5985/wsman/" -Authentication "Kerberos" 
Import-PSSession $Session -AllowClobber
Run Code Online (Sandbox Code Playgroud)

但是,当我导入会话时,我得到以下错误:

Import-PSSession : Proxy creation has been skipped for '%' command, because PowerShell couldn't verify its name as safe.
At line:1 char:17
+ Import-PSSession <<<<  $Session -AllowClobber
    + CategoryInfo          : InvalidData: (:) [Import-PSSession], InvalidOperationException
    + FullyQualifiedErrorId : ErrorSkippedUnsafeCommandName,Microsoft.PowerShell.Commands.ImportPSSessionCommand
Import-PSSession : Proxy creation has been skipped for '?' command, because PowerShell couldn't verify its name as safe.
At line:1 char:17
+ Import-PSSession <<<<  $Session -AllowClobber …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-2.0 powershell-remoting

9
推荐指数
1
解决办法
2万
查看次数

使用对象模型配置sharepoint站点订阅用户帐户目录路径

我正在使用sharepoint进行多租户配置,而我无法确定是否可以使用sharepoint对象模型为站点订阅设置用户帐户目录路径.我知道这可以通过PowerShell使用以下cmdlet来完成.

    $sub = New-SPSiteSubscription 
    $sub | Set-SPSiteSubscriptionConfig -UserAccountDirectoryPath "OU=AlpineBikeStore,OU=Hosting,DC=contoso,DC=com" -FeaturePack "50976ac2-83bb-4110-946d-95b4b6e90d42" -Confirm:$false 
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经获得了以下代码,这些代码将使用默认网站和功能包创建网站订阅.但是,我无法弄清楚如何在活动目录中设置用户OU的路径.

    //Create a default admin site for this tenant
    var site = new SPSite("https://contoso.com/", userToken);

    //Create the subscription and assign the default admin site to it.
    var sub = SPSiteSubscription.Create();
    sub.Add(site);

    //Get the feature pack and assign it to the subscription
    var featurePacks = SPSiteSubscriptionSettingsManager.Local.GetAllFeaturePacks();
    var pack = featurePacks.SingleOrDefault(x => x.Id == Guid.Parse("50976ac2-83bb-4110-946d-95b4b6e90d42"));
    SPSiteSubscriptionSettingsManager.Local.AssignFeaturePackToSiteSubscription(pack, sub);
Run Code Online (Sandbox Code Playgroud)

有什么建议?

sharepoint sharepoint-2010 sharepoint-object-model

7
推荐指数
1
解决办法
1837
查看次数

BsonClassMapSerializer 已经为 AbstractClassSerializer 注册

我正在使用 Mongo c# 驱动程序 2.0,并且在为我的 Id 值对象注册 AbstractClassSerializers 时遇到了 BsonSerializer 注册问题。

MongoDB.Bson.BsonSerializationException:已经有一个为 HistoricalEventId 类型注册的序列化程序。

当我查看 BsonSerializer 时,我看到 BsonClassMapSerializer 已经为我的类型注册了。

在此处输入图片说明

我假设正在为我的实体类型创建一个 BsonClassMapSerializer 并且它还为 Id 字段创建一个 BsonClassMapSerializer 。有没有人遇到过这个?如果有帮助,Bson 序列化程序代码如下所示。

抱歉,如果格式错误,c# 似乎不能很好地显示。

HistoricalEventIdBsonSerializer

public class HistoricalEventIdBsonSerializer : ToObjectIdBsonSerializer<HistoricalEventId>
{
    public override HistoricalEventId CreateObjectFromObjectId(ObjectId serializedObj)
    {
        HistoricalEventId parsedObj;
        HistoricalEventId.TryParse(serializedObj, out parsedObj);
        return parsedObj;
    }
}
Run Code Online (Sandbox Code Playgroud)

ToObjectIdBsonSerializer

public abstract class ToObjectIdBsonSerializer<T> : AbstractClassSerializer<T> where T : class
{
    private static readonly Type _convertibleType = typeof(IConvertible<ObjectId>);
    public abstract T CreateObjectFromObjectId(ObjectId serializedObj);

    public override T Deserialize(BsonDeserializationContext context, …
Run Code Online (Sandbox Code Playgroud)

mongodb-.net-driver

3
推荐指数
1
解决办法
2741
查看次数