PowerShell: Starting the CLR Failed with HRESULT 8007000e - powershell

I'm getting the following error when running PowerShell scripts on a remote server:
Starting the CLR Failed with HRESULT 8007000e
This is basically how I'm running/calling the scripts:
On the local server I'm running a CMD script that calls a PowerShell script to create a remote session to a remote server. In the PowerShell script I also call a CMD script to run on the remote server like so:
$Script = [scriptblock]::create("cd $BuildPath | cmd.exe /c install.cmd $apptype")
The install.cmd script runs on the remote server and calls a PowerShell script that executes a series of tasks.
powershell ./Install.ps1 -BuildNum %BUILDNUM%
After the tasks are complete, the PowerShell script then calls another PowerShell script to run a separate series of tasks. This is when I hit the above error, when the second PowerShell script is called.
This is how the second PS1 script is called from the first PowerShell script:
powershell "& {. $BinToolsSrc\PostInstallValidation.ps1 -BuildNum $BuildNum -Test 'True'; Run-Validation -App $App -AppLoc $AppLoc -Env $Env:ENV -Site $Site -AppPool $AppPool -Config $Config -EnvConfig $EnvConfig -DllPath $DllPath}"
What usually causes the type of CLR error that I'm getting and how do I resolve it?
NOTE: I do not get this error when I run the install script locally on the remote server.
Thanks in advance!
UPDATE: Installing PowerShell 3 on the remote server seems to have solved the problem as it targets the .NET 4.0 runtime.

I too had the same problem because I have changed some path settings in my VScode unknowingly.
I have changed the settings to command prompt which works fine for me now...(This might not be the best solution though).screenshot

Related

Remote Powershell script causes Selenium to timeout

When I use Invoke-Command from a Powershell script to run an .exe that uses Selenium Chromedriver, the execution of my .exe hangs until I get a timeout exception.
I have tried running the .exe with a local Powershell command, and it works just fine every time. It is only when I use Invoke-Command that the .exe stops working. Is there any way to actually run powershell scripts remotely, without Invoke-Command because Invoke-Command doesn't seem to be doing what I want it to.
I've also tried to -Wait the process of the .exe but it still hangs.

Powershell script failing from teamcity, running fine upon manual run

I have a powershell script which creates a new login in a database.
The script runs fine when I run from powershell ISE or console but it fails when I run it from Teamcity or use teamcity command manually.
C:\windows\sysnative\cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -File C:\DB_Deploy\DB_Deploy.ps1 && exit /b %ERRORLEVEL%
The error I get is
Validation Error: Error while checking backup file
The .bak backup file is at a shared remote location.
I suppose the problem, while running from teamcity, is in opening the backup file.
The same runner config works for other powershell scripts, the ones not involving opening of any file on remote location.

How to continue executing a Powershell script after starting a web server?

I have a script which calls two other scripts.
script0.ps1
Invoke-Expression C:\script1.ps1
Invoke-Expression C:\script2.ps1
The first script starts a web server:
script1.ps1
./activate anaconda_env
cd C:\webserver
python api_server.py
The second script starts a ngrok service:
script2.ps1
./activate anaconda_env
cd c:\ngrok
./ngrok -subdomain=mysd 8000
The problem is that the script0.ps1 only executes script1.ps1. At this point the web server starts running in the console and so the second command of script0.ps1 is not executed.
How to make write the scripts so both commands are executed? Or, how to write just one script to execute all commands but in two separate consoles?
The final result should be:
1) a web server running in a console with activated anaconda environment
2) a ngrok service running in a console with with activated anaconda environment
Change Script1.ps1 to launch python as a job:
./activate anaconda_env
cd C:\webserver
Invoke-Command -ScriptBlock {.\python.exe api_server.py} -AsJob -ComputerName .
I don't have the specific script you're using, so I tested this with turtle.py which ships with 3.43 and it seems to work.
You don't need to use Invoke-Expression to run a Powershell script from another script. Just run it as if you're on the command line
c:\script1.ps1
c:\script2.ps1
Now if script1.ps1 starts a process that doesn't exit, it will halt execution for the next statements in the script, and thus also prevent the second script from running.
In most cases this sequential execution is exactly what you want.
In your case you can start the scripts asynchronously by using Start-Process.
So your main script becomes something like:
start-process c:\script1.ps1
start-process c:\script2.ps1
Start-Process basically starts a new command shell to run the statement in. Check out the docs for more info. There's a bunch of parameters you can use to tweak how this happens.
To not have invoke-expression close your script you can pipe the output to Out-Null. Your code above would look like:
Invoke-Expression C:\script1.ps1 | Out-Null
Invoke-Expression C:\script2.ps1 | Out-Null

How to call a sub script from the main script on a remote server

HI i am having problem in calling a sub script from the main script using powershell on a remote server
I have the main script which is call 1.ps1
the other script is called 2.ps1
Here are the scripts
1.ps1 contains this code &("C:\Users\test\Desktop\remotely run scripts\2.ps1")
2.ps1 contains this code new-item -type file c:\itworksagain.txt
I am running the command as follows:
invoke-command -computer "remoteServer" -filepath "C:\Users\test\Desktop\remotely run scripts\1.ps1"
I am getting an error
The term 'C:\Users\test\Desktop\remotely run scripts\2.ps1 is not recognized as the name of a cmdlet, function, ...
I should have noticed this before. You have the following in the script
&("C:\Users\test\Desktop\remotely run scripts\2.ps1")
The brackets in that line are telling PowerShell to run a subexpression called "C:\Users\test\Desktop\remotely run scripts\2.ps1" which is not a cmdlet, exe.... etc.
I think your issue might be addressed if you change the line to the following.
& "C:\Users\test\Desktop\remotely run scripts\2.ps1"
Update from comments
Your first script calls the second. The invoke command runs the first on the remote server. The script executing on the remote server calls the second script. The call is origination on the remote server so the call is relative to that server. It is looking for 2.ps1 on the remote server. You need to move that script to a central location and then call it from your first with a UNC path which powershell supports. For testing you can move 2.ps1 to the remote server and it should work.

Running remote scripts in powershell

I've successfully got winrm working and I'm able to run Enter-PSSession my-machine in the shell and subsequently enter commands. However, when I try to run a script that starts up a remote session, all subsequent calls are run on the local machine. For instance:
PS> test.ps1
Contents of test.ps1
Enter-PSSession remote-pcname
gc env:computername
prints out local-pcname instead of remote-pcname any idea why the script file is not honoring the remote session? It is definitely successfully connecting because when the script finishes I'm returned to the shell prompt of the remote machine.
The short answer is: Enter-PSSession is intended for interactive use. If you want to execute commands on a remote system from a script, use invoke-command.
A similiar thread on the Technet forums is here:
http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/90e92d4e-716b-4b4d-956f-d38645e5c035
For me it work as documented. Enter-PSSession start an interactive session, it's for interactive use.
So to execute a script you can use New-PSSession to create a session and Invoke-Command using the remote session you created with New-PSSession.