如何从二进制PowerShell Cmdlet访问模块的privatedata?

时间:2015-09-08 21:23:51

标签: c# powershell

在我的模块的psd1文件中,我定义了以下内容:

if ($MyInvocation.MyCommand.Module.PrivateData['verbose'])

我可以从常规(非二进制)Cmdlet访问PrivateData,如下所示:

 var privateData = (Dictionary<string, object>)MyInvocation.MyCommand.Module.PrivateData;
 WriteVerbose((string)privateData["verbose"]);

但是,我似乎无法从我的C#(二进制)模块中遵循相同的模式。这是我试过的:

privateData

在尝试访问ServiceAppointment relatedAppt = (ServiceAppointment)OrganizationService.Retrieve( ServiceAppointment.EntityLogicalName.ToString(), email.new_RelatedServiceActivity.Id, new ColumnSet(true)); if (relatedAppt.StatusCode.Value == 4) //Do stuff 时抛出“对象引用未设置为对象的实例”。

1 个答案:

答案 0 :(得分:0)

我晚会晚了))

Hashtable privateData = (Hashtable)MyInvocation.MyCommand.Module.PrivateData;

if ((bool)privateData["verbose"])
{
    // Do stuff
}