I REALLY wanted to avoid posting here, but I’m out of ideas, and this continues on from a forum post Don Jones answered for me (https://powershell.org/forums/topic/what-is-powershell-made-from/). I posted on StackOverflow but I think the only answers I got were from posts I had googled previously and didn’t work for me.
This is one of the several different variations of me trying to call Get-SmbShare in C#:
private static void GetShareNames()
{
InitialSessionState iss = InitialSessionState.CreateDefault();
iss.ImportPSModule(new[] { "SmbShare" });
Runspace runspace = RunspaceFactory.CreateRunspace(iss);
runspace.Open();
PowerShell ps = PowerShell.Create();
ps.Runspace = runspace;
ps.Commands.AddCommand("Get-SMBShare");
foreach (PSObject result in ps.Invoke())
{
Console.WriteLine(result.Members["Name"].Value);
}
}
static void Main(string[] args)
{
GetShareNames();
}
I’m getting this error:
An unhandled exception of type 'System.Management.Automation.CommandNotFoundException' occurred in System.Management.Automation.dll Additional information: The term 'Get-SMBShare' 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.
I understand this isn’t really right for this forum, but I think if anyone will have a good idea of where I’m going wrong, it’s going to be this community.