Hi,
I am trying to register session configuration remotely but with no luck. I do not get errors but session still not registered on remote computer. Here is my code:
var runspaceConfiguration = RunspaceConfiguration.Create();
var runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
var MyCommand = new Command(" ");
runspace.Open();
var pipeline = runspace.CreatePipeline();
var password = new SecureString();
Array.ForEach("password".ToCharArray(), password.AppendChar);
var cred = new PSCredential("domainuser", password);
MyCommand = new Command("Invoke-Command -ComputerName " + host + " {$(Register-PSSessionConfiguration -Name HyperVRemoteAdmin -SessionType DefaultRemoteShell -AccessMode Remote -Force -RunAsCredential" + cred + ")}", true);
pipeline.Commands.Add(MyCommand);
var result = pipeline.Invoke();
PSObject retVal = new PSObject();
foreach (PSObject results in result)
{
if (results != null)
{
retVal = results;
Console.WriteLine(retVal);
}
}
Thanks in advance.