Run a 32 bit Powershell script on Sql Server Agent - powershell

I have a powershell script that runs a 32 bit com object so when I run it in Powershell 64x it fails but runs fine in 86x
When I run it in a Sql Server Agent job it has the same 64x failure.
Is there a way around this? Like SSIS packages?

You can directly invoke the 32-bit version of PowerShell by calling it through the WOW64 path:
%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe
Using the -File command line argument you can pass the name of the script you would like to run.

Related

Update pwsh with Scoop?

When trying to update Powershell Core with scoop via scoop update pwsh, I get the following error:
ERROR Application "pwsh" is still running. Close all instances and try again.
I tried closing PowerShell and updating via cmd, but it still throws that error.
Scoop uses pwsh.exe to execute the PowerShell scripts that scoop runs on. (scoop is 96% PowerShell) Even if run in cmd.exe, it will still use pwsh.exe to execute the scripts needed to scoop update pwsh. This problem is solved by using Windows PowerShell, (a.k.a. PowerShell 5 / powershell.exe) so scoop will execute the PowerShell scripts using that instead of pwsh.

How to run .ps1 script using powershell 64bit exe via jenkins?

Powershell workflow is not supported in powershell 32bit mode. Thus i want to execute the script using powershell 64bit mode.How to run .ps1 script in 64bit mode via jenkins?
You could create your custom powershell step like in this stackoverflow answer
Executing powershell command directly in jenkins pipeline
You'll have to replace powershell.exe by the path to your powershell 64b exe
You could also use a shebang. some literature on that at How can I use a shebang in a PowerShell script?
it works by calling using c:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe instead of c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe
find more information about sysnative at https://www.thewindowsclub.com/sysnative-folder-in-windows-64-bit
I confirm that calling:
%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe -executionpolicy Unrestricted -file "%~dp0\file.ps1"
results in the 64 bit powershell.
One can validate inside their script by printing out debug of:
$GE_64BitPS_Status=[System.Environment]::Is64BitProcess
write-host $GE_64BitPS_Status

Installing Pester on Windows 7

I'm trying to run Pester tests on a Windows 7 machine. I followed the instructions from here, and I also installed PSGet and executed Install-Module Pester.
This works on both the Windows 7 machines I have. I can run the pester tests from an elevated PowerShell console.
I have a .cmd file which runs the Pester tests, but I'm unable to run it from an elevated command prompt. This works on one Windows 7 machine, but it doesn't work on another one.
I followed the same instructions to install Pester on both the machines. Please suggest what I might be missing.
On the machine that 'doesn't work':
When I run the Pester script from PowerShell, the Invoke-Pester works and the script runs as expected. But, when I try to run the .cmd file which points to the pester scripts, I get an error saying Invoke-Pester is not recognized as a cmdlet, function; which means, as far as I understood, Pester is not working from the command prompt.
On the machine that 'works':
I am able to run the Pester script from both PowerShell and command prompt windows. The script runs as expected.
I found that the particular laptop I was working on, had some permission issues (corporate issues), and I couldn't get the Pester scripts working from the command prompt.
Anyway, I moved on to another Windows 7 laptop and installed Pester using the following instructions:
Download PsGet.psm1 from https://github.com/psget/psget/
Copy PsGet.psm1 to your modules folder (e.g. Modules\PsGet)
Start a new PowerShell session and import the Pester module using the commands below:
Get-Module -ListAvailable -Name Pester
Import-Module PsGet
Install-Module PsGet
Import-Module Pester.psm1
Install-Module Pester
Check the execution policy set on the computer with: Get-ExecutionPolicy. The output should be Unrestricted. Otherwise, run: Set-ExecutionPolicy Unrestricted

PowerShell: Starting the CLR Failed with HRESULT 8007000e

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

Powershell in SSIS

What would I need to do in order to run a PowerShell script in an SSIS package?
Does PowerShell need to be installed on the SQL server?
How do I actually call the script in SSIS?
Thanks
Yes, PowerShell needs to be installed. Then, you can use an Execute Process Task to point to the PowerShell executable and give the script as an argument.
Like so:
Executable: %windir%\system32\WindowsPowerShell\v1.0\powershell.exe
Arguments: C:\path\to\script.ps1