locked
メールボックスの削除プログラム RRS feed

  • 質問

  • PowerShellのフォーラムの方が正しいのかもしれませんが

    メールボックスを削除する以下の様なプログラムを作成して実行したところ

      Exception Message=この関数は現在のホストに実装されていないため、呼び出せません。

    とエラーが出てしまい上手く稼動いたしません。

    ワトソンログを見てみると以下のようにユーザの入力を待つためにうまく行かないようです。

    この入力を値固定で構わないのですがプログラムに挿入する方法を教えて頂けますようお願い致します。

    ----------------------------ワトソンログ-----------------------------------------------------------

       場所 System.Management.Automation.Internal.Host.InternalHostRawUserInterface.ThrowNotInteractive()
       場所 System.Management.Automation.Internal.Host.InternalHostUserInterface.PromptForChoice(String caption, String message, Collection`1 choices, Int32 defaultChoice)

    --------------------ここからプログラム-----------------------------------

     public string DisableMailbox(string UserID)
            {
                string Result = "";
                ICollection<PSObject> results;
                RunspaceConfiguration rc = RunspaceConfiguration.Create();
                PSSnapInException snapEx = null;
                PSSnapInInfo info = rc.AddPSSnapIn(
                    "Microsoft.Exchange.Management.PowerShell.Admin",
                    out snapEx);

                Runspace myRunSpace = RunspaceFactory.CreateRunspace(rc);
                myRunSpace.Open();

                // Create a pipeline...

                Pipeline pipeLine = myRunSpace.CreatePipeline();

                using (pipeLine)
                {
                    // disable-mailbox コマンド発行
                    Command newMbx = new Command("Disable-Mailbox");
                    newMbx.Parameters.Add("Identity", UserID);
                    // コマンド追加
                    pipeLine.Commands.Add(newMbx);

                    // 実行
                    results = pipeLine.Invoke();
                    if (pipeLine.Error != null && pipeLine.Error.Count > 0)
                    {
                        Result = Result + "ERROR: There were pipeline errors...\n";
                        foreach (object item in pipeLine.Error.ReadToEnd())
                        {
                            Result = Result + "Error: " + item.ToString() + "\n";
                        }
                    }
                }
                pipeLine = null;
                myRunSpace.Close();
                myRunSpace = null;
                return Result;
            }

    2007年5月15日 10:02

回答

  • 自己レスです。

     

    disable系のコマンドはExchange 管理シェルが自動的に Confirm パラメータを適用しまするのですね

    disable-mailbox -Identity "ユーザ" -ComfirmEmbarrassedFalse

    とすれば良いようですので

    プログラムのパラメータに

    System.Management.Automation.SwitchParameter SwFalse = false;

    newMbx.Parameters.Add("Confirm", SwFalse);
    を追加したら上手く稼動いたしました。

     

    2007年5月16日 3:16