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.
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.
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, "Deploy-Application.ps1");
string appDeployToolkitFolder = Path.Combine(currentAppFolder, "AppDeployToolkit");
string appDeployToolkitXMLPath = Path.Combine(appDeployToolkitFolder, "AppDeployToolkitConfig.xml");
string powershellExePath = Path.Combine(Environment.GetEnvironmentVariable("WinDir"), "System32\\WindowsPowerShell\\v1.0\\PowerShell.exe");
string powershellArgs = "-ExecutionPolicy Bypass -NoProfile -NoLogo -WindowStyle Hidden";
List<string> commandLineArgs = new List<string>(Environment.GetCommandLineArgs());
bool isForceX86Mode = false;
bool isRequireAdmin = false;
// Additional Customizations:
string appDeployStub = Path.GetFileNameWithoutExtension(currentAppPath);
string appDeployScriptName = appDeployStub + ".ps1";
appDeployScriptPath = Path.Combine(currentAppFolder, appDeployScriptName);
// End of Customizations
</code>
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
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.