wpfアプリケーションは、開発されたコンピュータで正常に動作しています。 bin/Releaseのファイルは、アプリケーションの実行に使用されます。 System.Management.Automation.dllは、新しいメールボックスを作成するためにExchange Server 2010上でリモートでpowershellを使用するために使用されます。 Local = Trueの設定であるので、dllはbin/releaseのファイルに追加されます。共通言語ランタイムが無効なプログラムを検出しました
ただし、bin/releaseの同じファイルが別のコンピュータにコピーされている場合、メールボックス作成部分を除いてActive Directoryのすべての機能が正常に動作しています。エラー:Common Language Runtimeが無効なプログラムを検出しました。
「コードの最適化」のチェックを外してVSで再構築することについてアドバイスをいくつか見つけることができますが、それは役に立たないようです。
私が前に言ったように、すべては開発者のコンピュータでうまくいきます。したがって、私はVS 2013もインストールされている別のコンピュータでこのアプリケーションを実行し、エラーが発生しました。「コマンドレット、関数、スクリプトファイル、または実行可能プログラムの名前として「Enable-Mailbox」という用語は認識されません。またはパスが含まれている場合は、パスが正しいことを確認して、もう一度やり直してください。ここで コードです:
public static class ManageMailBox
{
public static bool CreateMailBox(string strUserID, string admin_user, string pword) //, string str_upn)
{
try
{
string strExchangeServer = Constants.ExchangeServer;
Uri uri = new Uri(@"http://" + strExchangeServer + @"/powershell?serializationLevel=Full"); // orig works
/// must pass secure string
char[] passwordChars = pword.ToCharArray();
SecureString password = new SecureString();
foreach (char c in passwordChars)
{
password.AppendChar(c);
}
PSCredential credential = new PSCredential("DOMAIN\\" + admin_user, password);
Runspace runspace = RunspaceFactory.CreateRunspace();
PowerShell powershell = PowerShell.Create();
PSCommand command = new PSCommand();
command.AddCommand("New-PSSession");
command.AddParameter("ConfigurationName", "Microsoft.Exchange");
command.AddParameter("ConnectionUri", uri);
command.AddParameter("Credential", credential);
command.AddParameter("Authentication", "Default");
PSSessionOption sessionOption = new PSSessionOption();
sessionOption.SkipCACheck = true;
sessionOption.SkipCNCheck = true;
sessionOption.SkipRevocationCheck = true;
command.AddParameter("SessionOption", sessionOption);
powershell.Commands = command;
try
{
// open the remote runspace
runspace.Open();
// associate the runspace with powershell
powershell.Runspace = runspace;
// invoke the powershell to obtain the results
Collection<PSSession> result = powershell.Invoke<PSSession>();
foreach (ErrorRecord current in powershell.Streams.Error)
{
throw new Exception("Exception: " + current.Exception.ToString());
throw new Exception("Inner Exception: " + current.Exception.InnerException);
}
if (result.Count != 1)
throw new Exception("Unexpected number of Remote Runspace connections returned.");
// Set the runspace as a local variable on the runspace
powershell = PowerShell.Create();
command = new PSCommand();
command.AddCommand("Set-Variable");
command.AddParameter("Name", "ra");
command.AddParameter("Value", result[0]);
powershell.Commands = command;
powershell.Runspace = runspace;
powershell.Invoke();
// First import the cmdlets in the current runspace (using Import-PSSession)
powershell = PowerShell.Create();
command = new PSCommand();
//command.AddScript("Set-ExecutionPolicy -Unrestricted");
command.AddScript("Import-PSSession -Session $ra");
powershell.Commands = command;
powershell.Runspace = runspace;
powershell.Invoke();
// Now run get-ExchangeServer
powershell = PowerShell.Create();
command = new PSCommand();
command.AddCommand("Enable-Mailbox");
command.AddParameter("Identity", strUserID);
command.AddParameter("Alias", strUserID);
command.AddParameter("Database", "IAP Mailbox Database 0948752629");
powershell.Commands = command;
powershell.Runspace = runspace;
powershell.Invoke(); // ERROR !!! The term 'Enable-Mailbox' is not recognized as the name of a cmdlet, function
return true;
}
catch(Exception ex) {
throw new Exception(ex.Message.ToString()); }
finally
{
// dispose the runspace and enable garbage collection
runspace.Dispose();
runspace = null;
// Finally dispose the powershell and set all variables to null to free
// up any resources.
powershell.Dispose();
powershell = null;
}
}
catch (Exception argex)
{
throw new ArgumentException(argex.Message.ToString());
}
}
}
まず、アプリケーションが異なる権限セットで実行されていると思われます。クライアントマシンのadminとして実行してみてください。 – Karolis
アプリは、高い優先度のアカウントで「別のユーザーとして実行」として開かれており、問題のない別のマシンで新しいユーザーをアクティブディレクトリに作成することができます。しかし、Exhange Server 2010上に新しいメールボックスを作成するために、開発者のマシンでうまくいき、他のコンピュータでエラーを出すだけです。このメールボックスの部分では、ユーザーのログインとパスワードはポップアップウィンドウから送信され、Exchange Server 2010と連携するためにpowershellに渡されます。 – user5237764
ログを追加します。もう一度実行してください。ネットワークの制限があります。 – Karolis