1

タイトルはそれをすべて説明しています。Exchange Server で実行されていない C# アプリケーションがあります。メールボックスを作成できる必要があります。このチュートリアルを使用しようとしましたが、PowerShell IIS 仮想ディレクトリで次のことを行う必要があります。

  1. SSL を必要としない
  2. 基本認証を許可する

これは私たちができないことです。これにより、2 つの解決策が考えられます。上記のチュートリアルを変更して、これら 2 つの制限を必要としないようにする方法はありますか、または Power Shell をまったく使用せずにそれを行う方法はありますか?

リンクに行きたくない場合に備えて、コードは次のとおりです。


using System;
using System.Security;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace PowerShellTest
{
    class Program
    {
        static void Main(string[] args)
        {

            // Prepare the credentials that will be used when connecting
            // to the server. More info on the user to use on the notes
            // below this code snippet.
            string runasUsername = @"username";
            string runasPassword = "password";
            SecureString ssRunasPassword = new SecureString();
            foreach (char x in runasPassword)
                ssRunasPassword.AppendChar(x);
            PSCredential credentials =
                new PSCredential(runasUsername, ssRunasPassword);

            // Prepare the connection
            var connInfo = new WSManConnectionInfo(
                new Uri("http://ServersIpAddress/PowerShell"),
                "http://schemas.microsoft.com/powershell/Microsoft.Exchange",
                credentials);
            connInfo.AuthenticationMechanism =
                AuthenticationMechanism.Basic;

            // Create the runspace where the command will be executed
            var runspace = RunspaceFactory.CreateRunspace(connInfo);

            // generate the command parameters
            var testNumber = 18;
            var firstName = "Test";
            var lastName = "User" + testNumber;
            var username = "tuser" + testNumber;
            var domainName = "pedro.test.local";
            var password = "ActiveDirectoryPassword1234";
            var ssPassword = new SecureString();
            foreach (char c in password)
                ssPassword.AppendChar(c);

            // create the PowerShell command
            var command = new Command("New-Mailbox");
            command.Parameters.Add("Name", firstName + " " + lastName);
            command.Parameters.Add("Alias", username);
            command.Parameters.Add(
                "UserPrincipalName", username + "@" + domainName);
            command.Parameters.Add("SamAccountName", username);
            command.Parameters.Add("FirstName", firstName);
            command.Parameters.Add("LastName", lastName);
            command.Parameters.Add("Password", ssPassword);
            command.Parameters.Add("ResetPasswordOnNextLogon", false);
            command.Parameters.Add(
                "OrganizationalUnit", "NeumontStudents");

            // Add the command to the runspace's pipeline
            runspace.Open();
            var pipeline = runspace.CreatePipeline();
            pipeline.Commands.Add(command);

            // Execute the command
            var results = pipeline.Invoke();

            runspace.Dispose();

            if (results.Count > 0)
                Console.WriteLine("SUCCESS");
            else
                Console.WriteLine("FAIL");

        }
    }
}


4

2 に答える 2

1

AuthenticationMechanism多くの異なる'を使用して、いわゆるランスペースを設定できます。

以下を使用したコードサンプルについては、MSDNサイトにアクセスしてください。

  • 基本認証(例で使用されています)
  • 証明書認証
  • Kerberos認証
  • ネゴシエートされた認証

http://msdn.microsoft.com/en-us/library/ff326159(v=exchg.140).aspx

いずれにせよ、PowerShellをまだあきらめる必要はありません。

于 2012-02-23T17:33:36.313 に答える
1

そのブログ投稿のコードは少し壊れています。Pipelineクラスは、コマンドを作成するための非常に複雑な方法であり、コマンドの記述方法では、リモートのランスペースだけでなく、ランスペースのペア(1つはローカル、もう1つはリモート)を作成します。

さらに、IISの「基本」と「http」は「PowerShellにセキュリティと暗号化がない」という意味ではありません。WinRMレイヤーを介して送信されるものはすべて、デフォルトで暗号化されています。

Exchangeチームからのこのリンクは、C#でこれを行う正しい方法をかなりうまくカバーしています。

それで:

  • 別のセキュリティ層があるため、IISの「基本」について心配する必要はありません。
  • ExchangeチームのC#を使用すると、コードを半分に削減して高速化できます

また、100%クリスタルクリアであるために:

PowerShellを使用する場合を除いて、Exchange2010をリモートで管理することはできません。

お役に立てれば

于 2012-02-23T20:44:18.240 に答える