Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7974939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:31:10+00:00 2026-06-04T08:31:10+00:00

I need to be able to import a module that resides on a remote

  • 0

I need to be able to import a module that resides on a remote machine through a C# runspace.

To be clear what I mean by this: The service I’m creating resides on server A. It creates a remote runspace to server B using the method below. Through the runspace I’m trying to import a module on server B.

Here’s the method I’m using to make the remote call:

internal Collection<PSObject> RunRemoteScript(string remoteScript, string remoteServer, string scriptName, out bool scriptSuccessful)
    {
        bool isLocal = (remoteServer == "localhost" || remoteServer == "127.0.0.1" || remoteServer == Environment.MachineName);

        WSManConnectionInfo connectionInfo = null;

        if (!isLocal)
        {
            connectionInfo = new WSManConnectionInfo(new Uri("http://" + remoteServer + ":5985"));
        }

        PsHostImplementation myHost = new PsHostImplementation(scriptName);

        using (Runspace remoteRunspace = (isLocal ? RunspaceFactory.CreateRunspace(myHost) : RunspaceFactory.CreateRunspace(myHost, connectionInfo)))
        {
            remoteRunspace.Open();
            using (PowerShell powershell = PowerShell.Create())
            {
                powershell.Runspace = remoteRunspace;

                Pipeline pipeline = remoteRunspace.CreatePipeline();

                pipeline.Commands.AddScript(remoteScript);

                Collection<PSObject> results = pipeline.Invoke();

                remoteRunspace.Close();

                scriptSuccessful = myHost.ScriptSuccessful;
                return results;
            }
        }
    }

“remoteScript” is set to the Powershell script I want to run. For example:

"Import-Module Modulename;CustomCommand-FromModule -parameter(s) -ErrorAction stop"

The module is not packedged together it’s a psd1, psm1, and a bunch of script files that reside in C:\\Powershell\ModuleName on the remote server (server B) and I have tested and made sure that it is calling the ModuleName.psd1 file in the C:\\Powershell\ModuleName directory.

Inside the ModuleName.psd1 file is the line:

ModuleToProcess = 'ModuleName.psm1'

However I get a very weird error if I try to run it through the c# runspace.

If I send in the following as a parameter to “remoteScript”:

"Import-Module Modulename"

I get the following error:

System.Management.Automation.RemoteException: The module to process ‘ModuleName.psm1’, listed in field ‘ModuleToProcess’ of module manifest ‘C:\Powershell\ModuleName\ModuleName.psd1’ was not processed because no valid module was found in any module directory.

The module does exist in one of the “$env:PSModulePath locations and does show up if you run:

get-module -listAvailable

I have also tried putting in the fully qualified path to the ModuleName.psm1 file inside the psd1 file. When I do that (or what was suggested by x0n below) I get almost the exact same error:

The module to process ‘C:\Powershell\ModuleName\ModuleName.psm1’, listed in field ‘ModuleToProcess’ of module manifest ‘C:\Powershell\ModuleName\ModuleName.psd1’ was not processed because no valid module was found in any module directory.

At this point I’m really not sure where to go or even if this is actually possible. I’ve searched everywhere and found some things that seem related, but were never quite the same and tended to be problems I’ve already overcome or just haven’t (to my knowledge) come up against yet. Any help would be appreciated! Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:31:11+00:00Added an answer on June 4, 2026 at 8:31 am

    It’s been a little bit since I solved this so I apologize for the delay. The solution for this actually turned out to be rather easy, though a little weird.

    To fix this, in ModuleName.psd1 I commented out:

    ModuleToProcess = 'ModuleName.psm1'
    

    And I Added it to NestedModules instead:

    NestedModules = Join-Path $psscriptroot 'ModuleName.psm1'
    

    Frankly, I’m not exactly sure why this let the module load successfully, but it worked for me.

    It has been a little while since I solved this so it is possible there is some tiny step I missed here. If this doesn’t work for you, let me know what problem you run in to and then I can let you know if it was something additional I had to do. I am fairly certain this was all though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to run RegLoadKey() on a remote machine, and it
So I am creating a module and I have a screen that I need
I need to be able to import an Excel spreadsheet into a PostgreSQL database.
I have team members that need to be able to checkin VBA modules/classes created
Users of the website need to able to store images in their area ,
Need to be able to pull Magento products into an external template. Need to
I need to be able to disable the selection of future dates within the
I need to be able to scroll a RichTextBox to the bottom, even when
I need to be able to take EPS and PDF's and convert them to
I need to be able to tell if a link (URL) points to an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.