Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Register-PSSessionConfiguration remotely

$
0
0

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. 



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>