Hello, I ran into a strange problem when I was using PowerShell 5.1

Copper Contributor

I want to use the following command:

Call PowerShell script through CMD

 

C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe /c D:\\test.ps1 -test

 

 But I ran into a very strange problem. I have two windows hosts I run it on my test machine and it takes only a few hundred milliseconds, but I deploy it on another host with the same configuration and performance, and it takes three seconds to execute!!!!!!!!

As far as I can see, on windows where I deploy the service, every time I start PowerShell, the CPU will be 80-100%.

My system is windows server 2016.

My PowerShell version is 5.1

I hope the great God can answer. Thank you very much.

God is with you.

 

 

 

 

4 Replies

@hexler Ok, let's try and zoom in to the real problem ;) If you start PowerShell on the server, just start it without loading a script. How long does that take? What does the script do? And when you already have PowerShell running, it is faster if you start the script? (Should be faster because already in memory) 

Do you have some more information regarding your issue?

Do you have any update for us?
"/c" is not a PowerShell parameter. All PowerShell parameters begin with '-'.
Check for a profile on the problem server, or run the command with -NoProfile to avoid load it on any servers. Loading the profile might be adding the extra time that you are observing.