小编m0d*_*st0的帖子

如何在C#中管道Powershell命令

我们的目标是获取Exchange 2010网站的最小数据库,因此我尝试从c#运行以下powershell命令,

Get-MailboxDatabase -server Exchange2010 -Status | select-object Name,DatabaseSize
Run Code Online (Sandbox Code Playgroud)

我苦苦挣扎的问题是-如何通过Select子句命令传递管道。

这是我的尝试

WSManConnectionInfo wsConnectionInfo = new WSManConnectionInfo(new Uri("https://" + ExchangeSite + "/powershell?serializationLevel=Full"),
    "http://schemas.microsoft.com/powershell/Microsoft.Exchange", getCredential());
wsConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
wsConnectionInfo.SkipCACheck = true;
wsConnectionInfo.SkipCNCheck = true;

rsRemoteRunspace = RunspaceFactory.CreateRunspace(wsConnectionInfo);
rsRemoteRunspace.Open();
Pipeline pipeLine = rsRemoteRunspace.CreatePipeline();

Collection<PSObject> DatabaSize = null;

Command myCommand = new Command("Get-MailboxDatabase");
myCommand.Parameters.Add("Server", "Exchange2010");
myCommand.Parameters.Add("Status", null);
Command myCommand2 = new Command("Select-Object");
    myCommand.Parameters.Add("Name");
myCommand.Parameters.Add("DatabaseSize");
pipeLineMB.Commands.Add(myCommand);
pipeLineMB.Commands.Add(myCommand2);
DatabaSize = pipeLine.Invoke();
Run Code Online (Sandbox Code Playgroud)

但我明白了

"A parameter cannot be found that matches parameter name 'Name'."
Run Code Online (Sandbox Code Playgroud)

请记住,我不能使用SnapIn,因为代码必须在运行Exchange服务器上的cmdlet的客户端计算机上运行。

欢迎任何建议。

编辑

我应用了yamen建议的修复程序,并且能够调用该命令,但是当我尝试获取该值时,我得到:“对象引用未设置为对象的实例。” …

.net c# powershell exchange-server

5
推荐指数
1
解决办法
9757
查看次数

使用PowerShell v2从大文本文件中获取行的子集

我正在使用一个大文本文件,我的意思是超过100 MB大,我需要遍历特定数量的行,一种子集,所以我正在尝试这个,

$info = Get-Content -Path $TextFile | Select-Object -Index $from,$to
foreach ($line in $info)
{
,,,
Run Code Online (Sandbox Code Playgroud)

但它不起作用.就像它只获得子集中的第一行一样.

我没有找到有关Index属性的文档,所以这是可能的还是我应该尝试使用不同的方法考虑文件大小?

powershell text-files

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

用于密码验证的RegEx(ASP)

有人可以建议使用正则表达式来验证具有以下条件的密码.

  • 密码长度必须至少为12个字符
  • 密码不得以数字开头
    • 密码必须具有以下4个特征中的3个:
    • 至少一个大写字母(AZ)
    • 至少一个小写字母(az)
    • 至少一个数字(0-9)
    • 至少下列符号之一:连字符( - ),下划线(_),美元($),磅/哈希(#)

我正在使用vbscript和经典ASP.

在此先感谢,m0dest0

regex vbscript asp-classic

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

WCF - 无法获取元数据

它使用IIS 7在Intranet中运行,只要我在IIS管理器中启用匿名身份验证,它就可以正常工作.如果我禁用它并尝试使用wcftestclient运行它然后我得到以下错误,

Error: Cannot obtain Metadata from http://myserver/testing/eval.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error    URI: http://myserver/testing/eval.svc    Metadata contains a reference that cannot be resolved: 'http://myserver/testing/eval.svc'.    The HTTP request is unauthorized with client authentication scheme 'Anonymous'. 
Run Code Online (Sandbox Code Playgroud)

这是我的web.config文件,

<system.serviceModel>
<bindings>
    <wsHttpBinding>
        <binding name="Binding1">
            <security mode="Transport">
                <transport clientCredentialType="Windows" …
Run Code Online (Sandbox Code Playgroud)

c# wcf wcftestclient wcf-binding wcf-security

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

将其拆分为数组

我有这个代理地址字符串,它们用空格分隔,但是x400和x500将空格处理到它们的地址中.什么是拆分它的最佳方法.

例如

smtp:john@a-mygot.com smtp:john@b-mygot.com smtp:john@c-mygot.com X400:C=us;A= ;P=mygot;O=Exchange;S=John;G=Gleen; SMTP:john@mygot.com 
Run Code Online (Sandbox Code Playgroud)

预期结果:

smtp:john@a-mygot.com
smtp:john@b-mygot.com
smtp:john@c-mygot.com
X400:C=us;A= ;P=mygot;O=Exchange;S=John;G=Gleen;
SMTP:john@mygot.com
Run Code Online (Sandbox Code Playgroud)

谢谢,

编辑,

        string mylist = "smtp:john@a-mygot.com smtp:john@b-mygot.com smtp:john@c-mygot.com X400:C=us;A= ;P=mygot;O=Exchange;S=John;G=Gleen; SMTP:john@mygot.com X500:/o=Example/ou=USA/cn=Recipients of  /cn=juser smtp:myaddress";

        string[] results = Regex.Split(mylist, @" +(?=\w+:)");
        foreach (string part in results)
        {
            Console.WriteLine(part);
        }
Run Code Online (Sandbox Code Playgroud)

结果

smtp:john@a-mygot.com
smtp:john@b-mygot.com
smtp:john@c-mygot.com
X400:C=us;A= ;P=mygot;O=Exchange;S=John;G=Gleen;
SMTP:john@mygot.com
X500:/o=Example/ou=USA/cn=Recipients of  /cn=juser
smtp:myaddress
Run Code Online (Sandbox Code Playgroud)

c# string

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