PowerShell question and C#

This topic contains 2 replies, has 2 voices, and was last updated by  Steven Ayers 2 years, 7 months ago.

  • Author
  • #31306

    Steven Ayers

    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);
                PowerShell ps = PowerShell.Create();
                ps.Runspace = runspace;
                foreach (PSObject result in ps.Invoke())
            static void Main(string[] args)

    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.

  • #31308

    Dave Wyatt

    Is this a 32-bit executable, or 64-bit? On my system, the SmbShare module only exists for 64-bit PowerShell, for whatever reason, and your code may work fine if you compile it as x64.

  • #31310

    Steven Ayers

    In the hours I spent changing my code, how did I not think to check that out?

    Thank you! Problem solved.

You must be logged in to reply to this topic.