Command line argument

I have several deployments where I need to have it run based on location. Basically they are just config files that need to be copied depending on the location.

Instead of having two separate deployments, I would like to be able to set this as a command line argument that will pass into the script to deploy out the right config file.

So I have a deployment that has files for US and UK. I would like to be able to say Deploy-Application.Exe Install UK or US and this correspond to an if statement of sorts in the script it self.

For example: if cmdline = US { copy us file} elseif cmdline= UK {copy uk file}

I have tried to change the name of the powershell script to Deploy-Application_UK.ps1 and change the Deploy-Application.exe to Deploy-Application_UK.exe but it still wants to run the standard Deploy-Application.ps1 file.

Any thoughts?

Thanks in advance.

Might be easier to use the normal method for launching but hand out a write-host that asks for UK or US, sets a variable based on the response, then use a line with PS to run the copy function based off the variable it collected…

@Brian
This forum is meant for posts sharing completed functions with the community meant to extend the toolkit and provide functionality we haven’t built into the toolkit. Your post is better organized under the “General” forum for future reference.

Look at the documentation for the commandline options for Deploy-Application.exe. There is a switch that lets you specify the name of the file you want to execute.

Hello,

We also needed to name our installation scripts as well as the stub EXE based on our package naming standards and SOPs. So, we ended up adding three more lines (specified in the partial code below) to DeployApplication.cs and recompiled into EXE with those changes. This change allows us to rename Deploy-Application.EXE to any package name we want and it will look for PS1 file with the same name in the same folder. For example,
When “Adobe Acrobat XI.EXE” is executed it will look for “Adobe Acrobat XI.PS1” in the same folder by default.

As a side note, it would also be nice to have the ability to pass our custom command line arguments to Deploy-Application.EXE which wil in turn pass that to the PS1 file (i.e. similar to %CMDLINE% in WiseScript). Regards.

<code>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Windows.Forms;
using System.Reflection;

namespace PSAppDeployToolkit
{
    static class DeployApplication
    {
        public static void Main()
        {
            try
            {
                // Set up variables
                int processExitCode = 60010;
                string currentAppPath = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
                string currentAppFolder = Path.GetDirectoryName(currentAppPath);
                string appDeployScriptPath = Path.Combine(currentAppFolder, &quot;Deploy-Application.ps1&quot;);
                string appDeployToolkitFolder = Path.Combine(currentAppFolder, &quot;AppDeployToolkit&quot;);
                string appDeployToolkitXMLPath = Path.Combine(appDeployToolkitFolder, &quot;AppDeployToolkitConfig.xml&quot;);
                string powershellExePath = Path.Combine(Environment.GetEnvironmentVariable(&quot;WinDir&quot;), &quot;System32\\WindowsPowerShell\\v1.0\\PowerShell.exe&quot;);
                string powershellArgs = &quot;-ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden&quot;;
                List&lt;string&gt; commandLineArgs = new List&lt;string&gt;(Environment.GetCommandLineArgs());
                bool isForceX86Mode = false;
                bool isRequireAdmin = false;

                // Additional Customizations: 
                string appDeployStub = Path.GetFileNameWithoutExtension(currentAppPath);
                string appDeployScriptName = appDeployStub + &quot;.ps1&quot;;
                appDeployScriptPath = Path.Combine(currentAppFolder, appDeployScriptName);
                // End of Customizations
</code>

Never mind my side note above. You can already do that. :slight_smile:

Hi Husnu,

My apologies for opening an old thread and hopefully you can assist on finding the answer to your code posted above. As you can see from the screenshots below, I’m getting errors before I even recompile. Are you able to assist?

IDE: Microsoft Visual Studio Professional 2015
Environment: C#

I’m unable to embed the screenshots or post links. Trying Simple URLS

Code
Google Photos

Eror
Google Photos

Hi Gary,

It seems like the code that I posted is not displayed properly. For some reason, the symbols and quotes were replaced by some garbage. Here is a screenshot of that section.

I can also send you the code, if you still have problems figuring out by yourself.

Thank you Husnu. I will give this a try when I get back from travel. I appreciate the reply!