Import Modules from Server

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
bhnuser
Posts: 48
Last visit: Tue Nov 21, 2023 10:33 pm

Import Modules from Server

Post by bhnuser »

Hello everybody,

i'm a little desperate and my latin ends.

I am just about to add a PowerShell module for a created GUI. The problem is that the module is located as a folder on a server in the network. As a domain admin, I have the option of my user executing a simple Import-Module -Name <path as UNC>. Unfortunately, the users who are supposed to use the GUI are not domain admin. So they run into an error.

So I tried different solution approaches without success. Maybe you can help me with that?

How it works (for me as domain admin):

Code: Select all

Import-Module -Name "\\server.domain.com\c$\testpath\Modules\MSOnline\"
But for the other user i tested already this:
1. Try:

Code: Select all

$test = New-PSSession -ComputerName "server.domain.com" -Credential $Credentials
Import-Module -PSSession $test -Name "\\server.domain.com\c$\testpath\Modules\MSOnline\"
2. Try:

Code: Select all

Invoke-Command -ComputerName "server.domain.com" -Scriptblock {Import-Module -Name "\\server.domain.com\c$\testpath\Modules\MSOnline\"} -Credential $Credentials
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Import Modules from Server

Post by jvierra »

Sorry but regular users cannot remote.
Why are you using a session to import a module from a third server? Just import the module.
User avatar
bhnuser
Posts: 48
Last visit: Tue Nov 21, 2023 10:33 pm

Re: Import Modules from Server

Post by bhnuser »

jvierra wrote: Wed Mar 11, 2020 3:52 am Sorry but regular users cannot remote.
Why are you using a session to import a module from a third server? Just import the module.
Yea, i tried to import the module with the regular command. But there i can not refer some credentials.
So i hoped i can create a session to get the modules.
Mybe this information could help: I use in my tool a serviceuser, which is domain admin. I thought I could load the module from the server with this service user.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Import Modules from Server

Post by jvierra »

Why? Why do you need to import the module into a remote session? You cannot access a third server from a remote session with any account. It is restricted by Windows security.
User avatar
bhnuser
Posts: 48
Last visit: Tue Nov 21, 2023 10:33 pm

Re: Import Modules from Server

Post by bhnuser »

I already use this for installed Modules on remote server. I can get the module (like ActiveDirectory, Exchange on prem, S4B) from our server. But how i said, this module are already installed.

But i need now to import an Module, which is saved on our data storage in an folder. There are all .dll and psm1 files. But i can get this folder only with domain admin
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Import Modules from Server

Post by jvierra »

That is correct. Only a domain admin can use remoting but, even with \remoting you cannot access a UNC path.
#1 will work with admin credentials.
#2 won't work at all.
User avatar
bhnuser
Posts: 48
Last visit: Tue Nov 21, 2023 10:33 pm

Re: Import Modules from Server

Post by bhnuser »

Thank you for the information.
I found now my issue. I need write the full path till the .psd1-File. Strangely the normal Import-Module works without the full path.
But i've now a new question. Is it possible to make the import faster?

I mean, when i use Import-Module -Name ... it taks only 2,5 sec.
When I use Import-Module -Name ... -Session ... it takes 17 sec.
I use the .psd1-File with both variants
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Import Modules from Server

Post by jvierra »

That would be something you would have to troubleshoot on your network.
User avatar
bhnuser
Posts: 48
Last visit: Tue Nov 21, 2023 10:33 pm

Re: Import Modules from Server

Post by bhnuser »

It's fixed now. Was an issue from our network. It runs now in few seconds.

But i have an other question to pssession. If i create a session with New-PSSession then i can see a new process on the remote computer called "wsmprovhost.exe". This can opend only 5 times by default of winrm (MaxShellsPerUser). Is it possible to create a new option-/configurationfile with a higher count of MaxShellsPerUser and use this with New-PSSession (SessionOption / ConfigurationOption) ?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Import Modules from Server

Post by jvierra »

Why would you need more than one session per user. It sounds like you are creating a new session for each command. That is not how to use remoting. create a session once and reuse it. That is what a session is for.

To increase the number of session you would need to reconfigure the remote systems and restart WinRM.

First review the design and implementation of your script to see why you are using multiple sessions and if it is necessary.
For maintaining a session we can create a remote disconnected session and multiple processes can connect to the remote session and submit scripts then disconnect. This allows one persisted session that can run across local restarts and can be reused across local user logons.
This topic is 4 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked