Exchange 2007 Powershell管道错误 [英] Exchange 2007 Powershell Pipeline Error

查看:99
本文介绍了Exchange 2007 Powershell管道错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

当我尝试运行一些代码来管理我的Exchange邮箱时,我收到了以下错误。

输入对象无法绑定到命令的任何参数,因为该命令不接受管道输入或输入及其属性与管道输入的任何参数都不匹配。

这是我的代码:


Hello,

I am getting the follwoing error when I try to run some code to manage my Exchange mailboxes.

The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.

Here is my code:

 
































































































































































































































































































1 RunspaceConfiguration rsConfig = RunspaceConfiguration 。Create();
2
3 PSSnapInException snapInException = null ;
4
5
6 Console.WriteLine (QUOT; MS载入插件的Exchange");
7
8 PSSnapInInfo psinfo = rsConfig AddPSSnapIn(QUOT; Microsoft.Exchange.Management.PowerShell.Admin" ;,出snapInException);
9
10 Runspace myRunSpace = RunspaceFactory CreateRunspace(rsconfig配置);
11
12
13 Console.WriteLine(" Open the Runspace");
14
15 myRunSpace.Open();
16
17
18 Console.WriteLine(" Opening) );在PowerShell中"邮箱的使能命令;
19
20 命令 myCommandEnable = new 命令("启用邮箱");
21
22
23 Console.WriteLine("将参数添加到启用邮件中) -box指挥QUOT);
24
25 myCommandEnable.Parameters.Add("同一性QUOT ;,用户名);
26
27 myCommandEnable.Parameters.Add("别名" ;,别名);
28
29 myCommandEnable.Parameters.Add("数据库与QUOT ;, database.ToString());
30
31
32 Console.WriteLine(" Opening)设置邮箱命令PowerShell中的");
33
34 命令 myCommandSet1 = new 命令("设置邮箱");
35
36
37 Console.WriteLine("将参数添加到Set-邮箱命令");
38
39 myCommandSet1.Parameters.Add("同一性QUOT ;,用户名);
40
41 myCommandSet1.Parameters.Add(" EmailAddressPolicyEnabled" ;, 0);
42
43 Command myCommandSet2 = new 命令("设置邮箱");
44
45 myCommandSet2.Parameters。添加(QUOT相同性QUOT ;,用户名);
46
47 myCommandSet2.Parameters.Add(" WindowsEmailAddress" ;, windowsemail);
48
49 myCommandSet2.Parameters.Add(" EmailAddresses" ;,的emailList);
50
51
52 Console.WriteLine(" Opening)连接到SAM");
53
54
55 Console.WriteLine("打开管道到MS eXchange和SAM");
56
57 Pipeline myPipeline = myRunSpace CreatePipeline();
58
59 myPipeline.Commands。加入(myCommandEnable);
60
61 myPipeline.Commands.Add(myCommandSet1) ;
62
63 myPipeline.Commands.Add(myCommandSet2) ;
64
65 myPipeline.Commands.AddScript(samscript) ;
66
67 Console.ForegroundColor = ConsoleColor 红色。
68
69 Console.WriteLine( "运行命令");
70
71 Collection < PSObject > myPipeResults = myPipeline .Innoke();
72
73
74 Console.WriteLine (QUOT;检查错误");
75
76 if(myPipeline.Error!= null &&& myPipeline.Error.Count > 0)
77
78 {
79
80 Console.ForegroundColor = ConsoleColor 。洋红色;
81
82 Console.WriteLine( "中检测到错误查看下面的");
83
84
85 foreach(myPipeline.Error.ReadToEnd()中的对象项目)
86
87 {
88
89 Console.WriteLine(item.ToString());
90
91 }
92
93 }
94
1 RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();  
2  
3 PSSnapInException snapInException = null;  
4  
5  
6 Console.WriteLine("Loading MS Exchange Plugin");  
7  
8 PSSnapInInfo psinfo = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out snapInException);  
9  
10 Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsConfig);  
11  
12  
13 Console.WriteLine("Opening the Runspace");  
14  
15 myRunSpace.Open();  
16  
17  
18 Console.WriteLine("Opening Mailbox-Enable Command in PowerShell");  
19  
20 Command myCommandEnable = new Command("Enable-Mailbox");  
21  
22  
23 Console.WriteLine("Adding the Paramaters to the Enable Mail-Box Command");  
24  
25 myCommandEnable.Parameters.Add("Identity", username);  
26  
27 myCommandEnable.Parameters.Add("Alias", alias);  
28  
29 myCommandEnable.Parameters.Add("Database", database.ToString());  
30  
31  
32 Console.WriteLine("Opening Set-Mailbox Command in PowerShell");  
33  
34 Command myCommandSet1 = new Command("Set-Mailbox");  
35  
36  
37 Console.WriteLine("Adding the Paramaters to the Set-Mailbox Command");  
38  
39 myCommandSet1.Parameters.Add("Identity", username);  
40  
41 myCommandSet1.Parameters.Add("EmailAddressPolicyEnabled", 0);  
42  
43 Command myCommandSet2 = new Command("Set-Mailbox");  
44  
45 myCommandSet2.Parameters.Add("Identity", username);  
46  
47 myCommandSet2.Parameters.Add("WindowsEmailAddress", windowsemail);  
48  
49 myCommandSet2.Parameters.Add("EmailAddresses", emailList);  
50  
51  
52 Console.WriteLine("Opening Connection to SAM");  
53  
54  
55 Console.WriteLine("Opening Pipeline to MS eXchange and SAM");  
56  
57 Pipeline myPipeline = myRunSpace.CreatePipeline();  
58  
59 myPipeline.Commands.Add(myCommandEnable);  
60  
61 myPipeline.Commands.Add(myCommandSet1);  
62  
63 myPipeline.Commands.Add(myCommandSet2);  
64  
65 myPipeline.Commands.AddScript(samscript);  
66  
67 Console.ForegroundColor = ConsoleColor.Red;  
68  
69 Console.WriteLine("Running Command");  
70  
71 Collection<PSObject> myPipeResults = myPipeline.Invoke();  
72  
73  
74 Console.WriteLine("Checking for Errors");  
75  
76 if (myPipeline.Error != null && myPipeline.Error.Count > 0)  
77  
78 {  
79  
80 Console.ForegroundColor = ConsoleColor.Magenta;  
81  
82 Console.WriteLine("Errors were detected. View the Following");  
83  
84  
85 foreach (object item in myPipeline.Error.ReadToEnd())  
86  
87 {  
88  
89 Console.WriteLine(item.ToString());  
90  
91 }  
92  
93 }  
94  

推荐答案

那么你想要在你的运行空间中做什么呢?

看起来你正试图运行:
enable-mailbox .. | set-mailbox ... | set-mailbox ...

如果你试图运行上面的内容,我非常怀疑set-mailbox省略的对象可以是直接传递到另一个集邮箱...
So what is it exactly you're trying to do in your runspace?

Looks like you're trying to run:
enable-mailbox ..|set-mailbox ...|set-mailbox ...

If you are trying to run the above, I very much doubt the objects omitted by set-mailbox can be passed directly to another set-mailbox...


这篇关于Exchange 2007 Powershell管道错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆