2016-07-06 25 views
-2

PowerShellのPreStage ADアカウントをC#から使いこなそうとしていますが、このコードでは内部エラーが発生しています。誰かが私が間違っていることを見てくださいできません。Cでnew-ADComputer powershellを実行するには

PowerShell ps = PowerShell.Create(); 
ps.Commands.AddCommand("Import-Module").AddArgument("ActiveDirectory"); 
ps.Invoke(); 
ps.Commands.Clear(); 
ps.Commands.AddCommand("New-ADComputer"); 
ps.AddParameter("-Name", "'TESTESTS'"); 
ps.AddParameter("-SamAccountName", "'TESTESTS'"); 
ps.AddParameter("-Path", "'OU=Computers,OC=YRMC,DC=myorginization,DC=local'"); 

try 
{ 
    ps.Invoke(); 
    Console.ReadKey(); 
} 
catch (Exception e) 
{ 
    Console.WriteLine(e.ToString()); 
    Console.Read(); 
} 

例外

System.Management.Automation.CmdletInvocationException: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs. ---> Microsoft.ActiveDirectory.Management.ADException: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs. ---> System.ServiceModel.FaultException: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs. 
    --- End of inner exception stack trace --- 
    at Microsoft.ActiveDirectory.Management.AdwsConnection.ThrowException(AdwsFault adwsFault, FaultException faultException) 
    at Microsoft.ActiveDirectory.Management.AdwsConnection.Create(ADAddRequest request) 
    at Microsoft.ActiveDirectory.Management.ADWebServiceStoreAccess.Microsoft.ActiveDirectory.Management.IADSyncOperations.Add(ADSessionHandle handle, ADAddRequest request) 
    at Microsoft.ActiveDirectory.Management.ADActiveObject.Create() 
    at Microsoft.ActiveDirectory.Management.Commands.ADNewCmdletBase`3.ADNewCmdletBaseProcessCSRoutine() 
    at Microsoft.ActiveDirectory.Management.CmdletSubroutinePipeline.Invoke() 
    at Microsoft.ActiveDirectory.Management.Commands.ADCmdletBase`1.ProcessRecord() 
    --- End of inner exception stack trace --- 
    at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input) 
    at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke) 
    at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync) 
    at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings) 
    at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings) 
    at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings) 
    at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings) 
    at System.Management.Automation.PowerShell.Invoke() 
    at Test_Methods.Program.Main(String[] args) in C:\Users\rubotha\documents\visual studio 2015\Projects\Test Methods\Test Methods\Program.cs:line 45 
+0

を参照してください。a)これは「エラーを推測する」ゲームですか? b)OC = YRMC?それはOUかDCか? – TessellatingHeckler

+0

そのOU、それは残念です...それは男性のコーディングの長い一日だったと私は本当に疲れていた私はそれを試してみて、それが私の問題を修正するかどうかを確認してください。 – Ruan33

+0

@TessellatingHecklerこれは私の問題を解決しませんでした。私はそれが問題であれば、それは道を見つけることができないと私に言っただろうからではないと分かっていた。 – Ruan33

答えて

0

メッセージは明白であり、あなたは、例外の詳細を取得したい場合、あなたは.configファイルで設定する必要があります:多くのため

<serviceDebug includeExceptionDetailInFaults="true" /> 

を参照してください。詳細:Turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server

PSコードが正しく動作するようにするには、PSから直接実行してくださいコマンドプロンプトからコマンドpowershell

New-ADComputer -Name 'TESTESTS' -SamAccountName 'TESTESTS' -Path 'OU=Computers,OC=YRMC,DC=myorginization,DC=local' 

を実行し、それが動作するかどうかを確認。詳細については、https://technet.microsoft.com/en-us/library/ee617245.aspx

最後に、あなたがPSをC#から呼び出す必要はありません。 Add enabled Computer to Active Directory OU

+0

私はC#メソッドを使用して終了し、それは働いた。助けてくれてありがとう! – Ruan33

関連する問題