Can Jenkins run executable files called through a PowerShell script? - powershell

I have to install a program on a Windows 8 server using Jenkins as a framework. I wrote a PowerShell script that does run and install executable files when run through the PowerShell console. This does not happen when I run the same scripts through Jenkins.
Nothing happens except the text I output does appear on Jenkins' console.
Can running an .exe be done on Jenkins through a PowerShell script? Please help! Thanks :)

Read a similar answer here:
Open Excel on Jenkins CI
The issue is that Jenkins on Windows usually runs in "Session 0". Which is not visible to the logged in user. The trick is to launch the process (Excel in that answer, PowerShell in your case) in session 1.

Related

Win'2019 is detecting my scripts with the Win32/Casur.A!cl trojan

I have a windows batch script that, depending on the user menu selection, opens a powershell.exe and passing a variable to run a .ps1 script. I then use Bat To Exe Converted (v3.0.10) to convert it to an exe. A few hours ago I made changes to the PS script and copied it to the Win'2019 server and it accepted it. Now, I just changed two letters in a write-host message command and it keeps quarantining the file. Since this will be passed to customers I can't be telling them to ignore it or white list it.
I'm guessing the .bat and .ps1 files are throwing Windows Defender off. Funny how it was fine just a few hrs ago. Even if I undo the 2 letters I added it still deleting the exe.
The .bat is quite big and it'd be very difficult for me to convert and add inside the .ps1 script in hope of not setting off the trojan. What other options do I have to fix this? Is there a process or url to notify MS about this to get them to fix this false positive?
NOTE: No other Windows version or 3rd party antivirus that I've tried is detecting the exe infected. Only Win'2019's Defender is.
It looks like MS has fixed the false-positive with my code. I came in to work this morning and tried to copy the exe again and this time it worked. I didn't even contact MS (we don't have a support contract anyway).
Btw the exe consisted of a bat and ps1 script that just downloads some public install files (such as 7zip) from an https address, saves them and when running the exe the user would just get a menu of which of the downloaded programs they want to install.
The issue can be reproduced creating a simple new console application (Language : C++) with Visual Studio 2019 (Community Edition) and then just run program: Ctrl + F5. The solution that worked for me, to run the program, was to add the folder as an exclusion in Windows Defender Antivirus. I couldn't find any solution on other threads

Why PowerShell opens a new window when running exe

I have a PowerShell script like this:
$tfExe = path/to/tf.exe
& $tfExt ... do something
On my computer (and other PCs) if I run this script I get the .exe output in my PowerShell window.
When I run the script on another computer (with Windows 7 32-bit) it opens a cmd window, the output displayed there, and the window is immediately closed.
The issue occurs for each .exe tool, even in robocopy.
Why does this happen and how can I change it?
I had another issue with my PowerShell and the solution to that issue also solved this issue.
In my PATHEXT environment variable I didn't have .exe. When I added it, the issue solved and all the .exe tools ran smoothly and the output appears in the PowerShell window.
I had a similar issue and figured out I had deleted the folder I was executing the commands from.
PATHEXT was ok:
But this was not (I had deleted it outside of PowerShell - oops):
Navigating to another path solved the issue.
You are starting an external exe, so it's working as intended. You could however try using cmd.exe /K - more info here https://ss64.com/nt/cmd.html

Cannot configure a TFS build agent with Powershell ISE

After downloading the vNext build agent from VSTS page or from on-premises TFS, I followed the steps to configure agent in Powershell ISE.
Upon running .\config.cmd, there is a display of >> Connect:
There is no other prompt further to proceed with the configuration like below.
Tried the same with Powershell console and it worked.
Why is it so? Why is it not working with ISE?
The PowerShell ISE does not support console applications that require interactive input. You can check this blog.
So you need to use PowerShell Console or Command Prompt to config build agent.

Script doesnt run from another script

I compiled an AutoIt script and uploaded it to a server. I then wrote a PowerShell script which downloads the compiled AutoIt script and runs it locally.
When I run the PowerShell script on Windows 7 it runs without issues. But when I run the PowerShell script from an application, the compiled AutoIt script does get downloaded but does not run to completion. It does appear in task manager.
Without seeing the script it is hard to say for sure. However, it might be a rights issue. Try adding this to the top of your script and see if it fixes the problem.
#RequireAdmin

Installing ABCPDF manually using powershell

We're setting up an automated build process using Teamcity
We need to have ABCPDF install itself automatically on each server, I'd like to be able to do this from the command prompt/powershell?
Has anyone done this?
Figured it out! Need to run powershell in 32bit mode for this to work.
$abcPdfPath = "C:\temp\abcpdf\ABCpdf.dll"
[Reflection.Assembly]::LoadFrom($abcPdfPath)
if ([WebSupergoo.ABCpdf9.XSettings]::InstallSystemLicense("cd9b5c07fb69sf2bf57c0a04d9bca58b10c44889c9fb197984e592f49addfce5ec5fe85d7b9205bc"))
{
"Successfully Installed"
}
else
{
"Failed"
}
EDIT
Teamcity runs in 64bit mode powershell which caused problems with the above script. There are two ways of getting around this. Once is to launch a 32bit version of powershell from powershell running the script. Alternatively; the approach we took was to create an executable with the above command and run that from powershell. This worked nicely.