PowerShell Session

Ask your Windows 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.
Locked
User avatar
bhnuser
Posts: 42
Joined: Fri Apr 06, 2018 7:35 am

PowerShell Session

Post by bhnuser » Wed Sep 19, 2018 4:20 am

Hello everybody,

i have a qustion to the PowerShell Sessions and can not find any answere to my problem.
I want to write a script that opens a PSSession to our exchange server to get the cmdlts from the exchange shell.
Unfortunately the pssession opens so slowly that i want to know how i can get it faster or how i can save the session on my computer to start it faster in a next scriptrun?
Is it possible? Or is there an other way?

Best regards

User avatar
jvierra
Posts: 13718
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: PowerShell Session

Post by jvierra » Wed Sep 19, 2018 4:27 am

Not really a scripting issue. The speed is dependent on the server. If it is very busy or low on resources it can be very slow.

There is no way to persist a session.

How long does Enter-PsSession take? 10 seconds is not abnormal.

User avatar
bhnuser
Posts: 42
Joined: Fri Apr 06, 2018 7:35 am

Re: PowerShell Session

Post by bhnuser » Wed Sep 19, 2018 4:55 am

Okay, thats sounds not so good. But asking costs nothing.
I've tried it now and it takes about 5 seconds to load the session and commands. Its not so long but how i can manage it, when i put this script in a task schedule and run this all 5 minutes? The script would opens all 5 minutes a new session or is there a way to save it?
I also think about this problem because I have a script that builds up three sessions in a row (Exchange, AD, Skype). With all three sessions the scripts starts 45-60 seconds.

User avatar
jvierra
Posts: 13718
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: PowerShell Session

Post by jvierra » Wed Sep 19, 2018 5:06 am

I cannot really understand what you are asking. Your English is a bit unclear.

User avatar
bhnuser
Posts: 42
Joined: Fri Apr 06, 2018 7:35 am

Re: PowerShell Session

Post by bhnuser » Wed Sep 19, 2018 6:22 am

What I want to say is that i will implement my script into a task scheduler that run every 5 minutes. This script will open each run a new session to the exchange. The question is whether i can save with the first run the session that my script doesnt open every time a new session to save time at the startup.

(This would help me also when I start my next script where i need to open three different sessions [AD, Exchange, Skype])

User avatar
jvierra
Posts: 13718
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: PowerShell Session

Post by jvierra » Wed Sep 19, 2018 6:25 am

And the answer is no.

Locked