I am trying to run the HPC cmdlet programmatically to change the HPC installation credentials on a remote computer. Running the cmdlet locally is pretty simple:
Runspace rs = GetPowerShellRunspace(); rs.Open(); Pipeline pipeline = rs.CreatePipeline(); PSCredential credential = new PSCredential(domainAccount, newPassword); Command cmd = new Command("Set-HpcClusterProperty"); cmd.Parameters.Add("InstallCredential", credential); pipeline.Commands.Add(cmd); Collection<PSObject> ret = pipeline.Invoke();
However, if I want to do the same with the remote PowerShell, I need to run Invoke-Command and pass the ScriptBlock credentials inside Command. How can i do this? It might look something like this, except that I need to pass the credentials as an object bound to the InstallCredential parameter inside the ScriptBlock instead of the line:
Pipeline pipeline = rs.CreatePipeline(); PSCredential credential = new PSCredential(domainAccount, newPassword); pipeline.Commands.AddScript(string.Format( CultureInfo.InvariantCulture, "Invoke-Command -ComputerName {0} -ScriptBlock {{ Set-HpcClusterProperty -InstallCredential {1} }}", nodeName, credential)); Collection<PSObject> ret = pipeline.Invoke();
source share