Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何通过C在powershell中传递一个应为$null的参数_C#_Powershell_Exchange Server 2010 - Fatal编程技术网

C# 如何通过C在powershell中传递一个应为$null的参数

C# 如何通过C在powershell中传递一个应为$null的参数,c#,powershell,exchange-server-2010,C#,Powershell,Exchange Server 2010,Exchange管理要求您将$null作为参数传递,以从邮箱中删除转发: 设置邮箱-ForwardingAddress$null-DeliverToMailboxAndForward$false 这句话的意思是: command = new PSCommand().AddCommand("Set-Mailbox"); command.AddParameter("Identity",task.TargetUser); command.AddParameter

Exchange管理要求您将$null作为参数传递,以从邮箱中删除转发:

设置邮箱-ForwardingAddress$null-DeliverToMailboxAndForward$false

这句话的意思是:

command = new PSCommand().AddCommand("Set-Mailbox");
          command.AddParameter("Identity",task.TargetUser);
          command.AddParameter("FowardingAddress", null);
          command.AddParameter("DeliverToMailboxAndForward", false);
ps.Commands=command;
var results = ps.Invoke();
不幸的是,ForwardingAddress设置上的调用阻塞:找不到与参数名称“FowardingAddress”匹配的参数


如何传递以$null结尾的参数?

如果该参数的类型为string,则您应该能够传递此值:

System.Management.Automation.Language.NullString.Value
或包括

using System.Management.Automation.Language;
后来

command.AddParameter("ForwardingAddress",NullString.Value);
另一个选项是通过AddScript方法使用$null:


如果该参数的类型为字符串,则应能够传递此值:

System.Management.Automation.Language.NullString.Value
或包括

using System.Management.Automation.Language;
后来

command.AddParameter("ForwardingAddress",NullString.Value);
另一个选项是通过AddScript方法使用$null:

传递null应该可以正常工作。如图所示,C的null被映射到$null

假设您显示的代码是直接从您的解决方案复制粘贴的,我猜问题在于您将值传递给参数FowardingAddress,而不是ForwardingAddress注意缺少的“r”。简单的打字错误,而不是类型不匹配:

传递null应该可以正常工作。如图所示,C的null被映射到$null



假设您显示的代码是直接从您的解决方案复制粘贴的,我猜问题在于您将值传递给参数FowardingAddress,而不是ForwardingAddress注意缺少的“r”。简单的打字错误,而不是类型不匹配:

你试过省略吗?@SteveMitcham-如果我没有设置转发地址,就不会修改转发地址对不起,误读了这个问题。你试过省略吗?@SteveMitcham-如果我没有设置转发地址,就不会修改转发地址对不起,误读了这个问题。我该如何将其放入我的c代码中?我有点困惑。System.Management.Automation.Language.NullString.values遗憾的是,它看起来很有希望,但还是出现了同样的错误:这就是我的胖手指综合症。我该如何在我的c代码中使用它?我有点困惑。System.Management.Automation.Language.NullString.values遗憾的是,它看起来很有希望,但还是出现了同样的错误:这就是我的胖手指综合症。自由形式的参数值是我的死亡。固定的谢谢,好眼力。在我看到丢失的“r”应该在哪里之前,我不得不看了这两个大约30秒。当脑自动校正:-呃。自由形式的参数值是我的死亡。固定的谢谢,好眼力。在我看到丢失的“r”应该在哪里之前,我不得不看了这两个大约30秒。当脑自动校正:-