internal PSModuleInfo LoadModuleByName(string name, bool loadToGlobalScope, bool importMembers = true) { // TODO: where do we handle FileNotFoundExceptions etc? var path = new Path(name).NormalizeSlashes(); if (name.Contains(path.CorrectSlash) || path.HasExtension()) { // check if it's already loaded var moduleInfo = _executionContext.SessionState.LoadedModules.Get(path); if (moduleInfo != null) { return moduleInfo; } // load it otherwise moduleInfo = LoadModuleByPath(path); // modules are loaded either to global or module scope, never to local scope var targetScope = loadToGlobalScope ? ModuleIntrinsics.ModuleImportScopes.Global : ModuleIntrinsics.ModuleImportScopes.Module; _executionContext.SessionState.LoadedModules.Add(moduleInfo, targetScope); if (importMembers) { _executionContext.SessionState.LoadedModules.ImportMembers(moduleInfo, targetScope); } return moduleInfo; } // otherwise we'd need to look in our module paths for a module throw new NotImplementedException("Currently you can only a specific module file, not installed modules"); }