Yes, you should be seeing a runtime exception:
Quote:
System.Management.Automation.RuntimeException occurred
HResult=0x80131501
Message="-LocalComputerName "$env:COMPUTERNAME" -Verbose is not a valid local computer name."
A quick
Google Search[
^] found this:
Executing PowerShell scripts from C# – Keith Babinec's Development Blog[
^].
Now, the script will look something like:
using (PowerShell PowerShellInstance = PowerShell.Create())
{
PowerShellInstance.AddScript("Test-Dtc -LocalComputerName param($param1) -RemoteComputerName param($param2) -Verbose");
var localComputer = Environment.GetEnvironmentVariable("COMPUTERNAME");
PowerShellInstance.AddParameter("param1", localComputer);
var remoteComputer = "[Remote Compter Name Goes Here]";
PowerShellInstance.AddParameter("param2", remoteComputer);
Collection<PSObject> PSOutput = PowerShellInstance.Invoke();
foreach (PSObject outputItem in PSOutput)
{
if (outputItem != null)
{
}
}
}
Full documentation found here:
Microsoft Documents - Powershell > Test-Dtc[
^]