Command line argument

//Command line argument
Command line argument 2015-06-18T14:39:12+00:00

The Toolkit Forums Toolkit Extensions Command line argument

  • Author
    Posts
  • Brian
    Participant
    Post count: 2
    #323 |

    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.

  • John
    Participant
    Post count: 2

    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…….

  • Muhammad Mashwani
    Keymaster
    Post count: 118

    @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.

  • Muhammad Mashwani
    Keymaster
    Post count: 118

    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.

  • Husnu
    Participant
    Post count: 5

    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.

    https://psappdeploytoolkit.codeplex.com/SourceControl/latest#Sources/Deploy-Application/Deploy-Application/DeployApplication.cs

    <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>
    • This reply was modified 2 years, 2 months ago by  Husnu.
    • This reply was modified 2 years, 2 months ago by  Husnu.
    • This reply was modified 2 years, 2 months ago by  Husnu.
    • This reply was modified 2 years, 2 months ago by  Husnu.
    • This reply was modified 2 years, 2 months ago by  Husnu.
    • Husnu
      Participant
      Post count: 5

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

  • Garry
    Participant
    Post count: 2

    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
    Env: C#

    • This reply was modified 1 year, 4 months ago by  Garry.
  • Garry
    Participant
    Post count: 2

    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
    https://goo.gl/photos/eo2qMRckGMs3y1Xs7

    Eror
    https://goo.gl/photos/uEB2GhB2CAUZTbjJ7

  • Husnu
    Participant
    Post count: 5

    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.

    http://screencast.com/t/Ij8NdGg7

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

  • gfunk99999
    Participant
    Post count: 1

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

You must be logged in to reply to this topic.