How to execute a 7zip sfx with extra command line parameters - command-line

I have an installer (installer.msi) and I made a self-extracting 7zip with a config file.
Here's my config file :
;!#Install#!UTF-8!
ExecuteFile="Installer.msi"
ExecuteParameters="TARGETDIR=\"[DirectoryPath]\" ALLUSERS=1"
;!#InstallEnd#!
These ExecuteParameters need to be embedded.
Now I have 2 scenario, I want to be able to execute it like normal or fully silent. To execute it fully silent I want to use the /qn switch when executing it from the command line :
.\installer.exe /qn
The problem is if ExecuteParameters is set in the config file, those extra parameters are ignored but works as expected when ExecuteParameters is not set (Tested it).
How can I give these extra parameters to the .msi without embedding it in the config file?

Related

Jenkins parameter Release versus Staging

I created a freestyle job in Jenkins that I just set up (latest version).
I added parameters to it. One of those is a Options selection for ReleaseType with the options of Staging and Release.
One of the build steps is executing a remote command on the server when the site is uploaded to. It uses the Execute Windows Batch Command build step.
Here is the command line (with things made generic):
sexec myuser#mysite.com -pw=mypassword -cmd="PowerShell -Command ""C:\batch\bvCopyFast.ps1 C:\inetpub\mysite${ReleaseType}\siteLoad C:\inetpub\mysite${ReleaseType}\site""
Basically I am executing a powershell command that uses Robocopy to copy the files from the upload folder to the actual release folder for the site.
As you can see I need to have the ${ReleaseType} replaced with the actual value. The problem is that when this gets executed it isn't doing the substitution. I just uses that literal value in the command and that doesn't work.
If you use the -Command parameter it implies you are going to write raw PowerShell code in between the quotation marks that follow (allow you can call a script as you have).
PowerShell -Command "Get-Date; pause;"
To call a PowerShell script file you should use:
PowerShell -File "Your-Script.ps1 -Parameter1 Argument1 -Parameter2 Argument2"
https://learn.microsoft.com/en-us/powershell/scripting/components/console/powershell.exe-command-line-help?view=powershell-6
I would write a PowerShell script that accepted your root path and the releaseType as arguments and execute that.
Param($rootPath,$releaseType)
{
robocopy "$($rootPath)\$($releaseType)\siteLoad" "$($rootPath)\$($releaseType)\site"
}
I have never used Jenkins so I hope this works as I expect it to!
sexec myuser#mysite.com -pw=mypassword -cmd=""PowerShell -File 'C:\batch\newScript.ps1' -RootPath 'c:\inetpub\mysite' -ReleaseType {ReleaseType}""

TeamCity running Powershell script, but failing to execute a batch file

I am currently in the process of implementing a deployment method using Teamcity, which runs a Powershell script on my Build Agent, which then configures my Production environment etc.
I have a problem with the Powershell script though, in that it can't seem to run the batch file from it.
The script runs perfectly if I run it manually, it only fails when run via TeamCity.
In the build log I am getting the error:
'myBatchFile.bat' is not recognized as an internal or external command, operable program or batch file.
The batch file and the powershell script are in the same directory and the batch file is called as such:
cmd /c Deploy.bat
I have my TeamCity configuration set up to have the build step for this as:
Script: File
ScriptExecutionMode: Execute script with -File argument
Script Arguments: None
Additional CMD line params: None
I had originally not used the cmd to try to execute the batch file, but executing the batch file like .\Deploy.bat did not seem to work either.
Is there an additional thing I need to set up in order to get the batch file to run? The rest of the script runs fine, just the call to the batch that doesn't.
This is a bit of a wild stab as it's difficult to predict what's happening, but from the description it seems like the path is been altered in the script and it's also dynamic as TeamCity creates temp directories, but if you replace:
cmd /c Deploy.bat
with
cmd /c "$(Split-Path $myinvocation.MyCommand.Path)\Deploy.bat"
then I think this will be able to located the deploy script.
Let me know how it goes.

Run a exe file through a power shell script

I want to run a power shell script which can run a exe file and following are my requirements.
I have that exe file in a remote server location(//ES-WEBSRV01/DBMigration) which is shared to my local machine. Also I want to run that ps file through a cmd.exe.
You can simply call it like any other program:
\\ES-WEBSRV01\DBMigration\something.exe
or, if it contains spaces somewhere along the path:
& "\\ES-WEBSRV01\DBMigration\some thing.exe"
I have no clue what you mean by »Also I want to run that ps file through a cmd.exe.«, though. If you mean that you need a batch file and want to run the PowerShell script from there, then:
powershell -file myscript.ps1

Disable powershell expansion of command's extension?

We have a lot of existing batch files that help with the running of different perl and ruby scripts.
A batch file (e.g. test.bat) would normally be invoked like:
$ test
and within the batch file, it will set some settings and finally try to run the corresponding script file (e.g. test.pl) like this:
perl -S "%0.pl" %*
All works with cmd.exe, but today, I decided to switch to PowerShell and found out that it expands the commands. So trying to run "test" will actually run "Full\path\test.bat" and my script would complain that there is no file test.bat.pl.
Is there a way to prevent this command expansion? Rewriting all batch files is not an option.
One way is to call cmd explicitly:
cmd /c test

Problem executing multiple powershell scripts from a batch file

I have a .bat that calls 3 PowerShell scripts
Basically the bat file looks like this
PScript1
Pscript2
Pscript3
After the Pscript1 the batch file does not execute Pscript2 or Pscript3, it stops and does not seem to return control to the batch file. Does anyone know what might cause this problem ?
In a batch file you would typically use && or || depending on whether or not you wanted the subsequent commands to run based on the success of previous commands e.g.:
powershell.exe .\PScript1.ps1 && powershell.exe .\PScript2.ps1
This invocation would execute the following command only if the preceeding command succeeded. You also need to specify powershell.exe as the EXE. The default action for a .ps1 is to open the file for editing.