Pass Command Line Switches to Program Being Run Remotely

Welcome Forums General PowerShell Q&A Pass Command Line Switches to Program Being Run Remotely

This topic contains 2 replies, has 2 voices, and was last updated by

7 months ago.

  • Author
  • #111934

    Points: 1
    Rank: Member


    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.

    [Parameter(Mandatory=$True,HelpMessage="6-digit Customer ID?")]
    [string] $CustomerId,
    [Parameter(Mandatory=$True,HelpMessage="Environment type [prod,test,dev]?")]
    [string] $EnvironmentType,
    [Parameter(Mandatory=$True,HelpMessage="Number of CTS Servers in Environment?")]
    [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.


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

  • #111943

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Check out Example 7 in the docs, mainly the second line of code in the example.

    That shows the correct way to pass multiple arguments.

  • #112007

    Points: 1
    Rank: Member

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

The topic ‘Pass Command Line Switches to Program Being Run Remotely’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort