I have seen quite a number of solutions, but none addresses my problem. I am trying to import a custom PowerShell module called "DSInternals" to my C# DLL.
https://github.com/MichaelGrafnetter/DSInternals
Everything in my code seems just fine, but when I try to get the available module it's not loaded.
The stream responds with
The term 'Get-ADReplAccount' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Where Am I going wrong with this code?
InitialSessionState init = InitialSessionState.CreateDefault();
init.ImportPSModule(new string[] { @"D:\\DSInternals\\dsinternals.psd1" }); //location of the module files
Runspace runspace = RunspaceFactory.CreateRunspace(init);
runspace.Open();
PowerShell ps = PowerShell.Create();
ps.Runspace = runspace;
ps.Commands.AddCommand("Get-ADReplAccount"); //this command is un-recognized
foreach (PSObject result in ps.Invoke())
{
Console.WriteLine(result); //this always returns null
}
ps.Streams.Error? - user4003407init.ThrowOnRunspaceOpenError=true;. - user4003407