Pass Command Line Switches to Program Being Run Remotely

Hello,

I am a PowerShell novice. I am trying to run a command remotely and pass command line switches. I have “borrowed” most of the code. I am struggling to make this work.

[CmdletBinding()]
param(
[Parameter(Mandatory=$True,HelpMessage="6-digit Customer ID?")]
[ValidateNotNullOrEmpty()]
[ValidateLength(6,6)]
[string] $CustomerId,

[Parameter(Mandatory=$True,HelpMessage="Environment type [prod,test,dev]?")]
[ValidateSet("prod","test","dev")]
[string] $EnvironmentType,

[Parameter(Mandatory=$True,HelpMessage="Number of CTS Servers in Environment?")]
[ValidateNotNullOrEmpty()]
[ValidateLength(1,2)]
[string] $ServerCount
)

Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"

if($EnvironmentType -eq 'prod') { $ServerNumber = 1} #Need loop here or some way to loop through the number of CTS servers
if($EnvironmentType -eq 'prod') { $DBPrefix = 'live'}
if($EnvironmentType -eq 'test') { $ServerNumber = 20}
if($EnvironmentType -eq 'dev') { $ServerNumber = 30}

$logdir = "C:\logs\WF"
if(!(test-path $logdir))
{
Write-Output "Creating directory $logdir"
New-Item -ItemType Directory -Force -Path $logdir
}

$ComputerName = "$($CustomerId)CTS$($ServerNumber)"
$FilePath = "\\$($CustomerId)API1\C$\Program Files (x86)\FakePath\Installation Manager\Packages\Installer.Modules.FakeProgram.2.6.0\SetupFiles\FakeSetup.exe"

Write-Host "Deploying Fake Program Setup to $ComputerName." -ForegroundColor Green

$MSIFile = Copy-Item $FilePath -Destination "\\$ComputerName\C$\BootStrap" -PassThru
$Confirm = Invoke-Command -ComputerName $ComputerName -ScriptBlock {
(Start-Process -FilePath "C:\BootStrap\$($Using:MSIFile.Name)" -ArgumentList "/passive /norestart" -Wait -PassThru -sqlconnectionstring bal:Overridable='yes' /Value='data source=fake_server;initial catalog=fake_db;UID=fake_dbuser;PWD=fake_dbpassword;Pooling=True;MultipleActiveResultSets=True;Application Name=Fake Program;').ExitCode
}

Write-Host "$ComputerName Done!" -ForegroundColor Green

I will be very grateful for any assistance.

-GH

EDIT: Line 41, specifically, is where I am struggling.

Check out Example 7 in the docs, mainly the second line of code in the example. https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-6

That shows the correct way to pass multiple arguments.

Don, thanks for the direction. The article was a big help.