The 'using module' statement into a ThreadJob's ScriptBlock

%3CLINGO-SUB%20id%3D%22lingo-sub-3070556%22%20slang%3D%22en-US%22%3EThe%20'using%20module'%20statement%20into%20a%20ThreadJob's%20ScriptBlock%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3070556%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20everyone!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20a%20question%20about%20the%20'using%20module'%20statement%20in%20Powershell.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20many%20class%20in%20different%20.psm1%20files%2C%20wich%20works%20perfectly%20with%20'using%20module'%20statement.%20But%20I%20nedd%20to%20import%20my%20class%20into%20a%20ThreadJob's%20ScriptBlock%20and%20'using%20module'%20do%20not%20be%20used%20after%20any%20statements%20in%20the%20script.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Capturar.PNG%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F341952i0EF2713D8A4010DC%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Capturar.PNG%22%20alt%3D%22Capturar.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20do%20not%20want%20use%20the%20'import-module'%20statement%2C%20because%20this%20statement%20not%20import%20class%20from%20.psm1%20files%2C%20only%20from%20ps1.%20I%20would%20have%20to%20change%20all%20my%20class%20files%20to%20.ps1%20and%20the%20'using%20module'%20do%20not%20work%20with%20.ps1.%20What%20would%20entail%20more%20and%20more%20problems.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E'using%20module'%20also%20works%20with%20relative%20path%2C%20import-module%20do%20not.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EExists%20one%20way%20to%20use%20the%20'using%20module'%20into%20a%20ScriptBlock%20or%20another%20way%20to%20delegate%20the%20imports%20between%20the%20scopes%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20help!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3070556%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Epwsh%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EThreadJob%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eusing%20module%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Senior Member

Hi everyone!

 

I have a question about the 'using module' statement in Powershell.

 

I have many class in different .psm1 files, wich works perfectly with 'using module' statement. But I need to import my class into a ThreadJob's ScriptBlock and 'using module' do not be used after any statements in the script. 

 

Capturar.PNG

 

I do not want use the 'import-module' statement, because this statement not import class from .psm1 files, only from ps1. I would have to change all my class files to .ps1 and the 'using module' do not work with .ps1. What would entail more and more problems.

 

'using module' also works with relative path, import-module do not.

 

Exists one way to use the 'using module' into a ScriptBlock or another way to delegate the imports between the scopes?

 

Thanks for help!

0 Replies