2017-07-14 5 views
1

Je suis totalement nouveau sur PowerShell. Tout ce que j'essaie de faire est d'appeler un fichier .exe sur un ordinateur distant en utilisant des paramètres nommés.Invoke-Command Start-Process avec des paramètres nommés

$arguments = "-clientId TX7283 -batch Batch82Y7" 
invoke-command -computername FRB-TER1 { Start-Process -FilePath "C:\Program Files (x86)\Acorne\LoadDen.exe" -ArgumemtList $arguments} 

Je reçois cette erreur.

A parameter cannot be found that matches parameter name 'ArgumemtList'. 
+ CategoryInfo: InvalidArgument: (:) [Start-Process], ParameterBindingException 
+ FullyQualifiedErrorId : NamedParameterNotFound, Microsoft.PowerShell.Commands.StartProcessCommand 
+ PSComputerName : FRB-TER1 

ArgumentList n'aime probablement pas les noms de paramètre. Pas certain.

Répondre

1

Cela devrait faire votre travail:

$arguments = "-clientId TX7283 -batch Batch82Y7" 
invoke-command -computername FRB-TER1 {param($arguments) Start-Process -FilePath "C:\Program Files (x86)\Acorne\LoadDen.exe" -ArgumemtList $arguments} -ArgumentList $arguments 
+0

Ai-je besoin d'arguments ArgumentList $ deux fois? Néanmoins, me donne toujours la même erreur. – zorrinn

+0

J'ai supprimé l'ArgumentList supplémentaire et essayé. Cette fois, il est dit: Impossible de valider l'argument sur le paramètre 'ArgumentList'. L'argument est nul ou vide. – zorrinn

+0

@zorrinn: Ce n'est pas additionnel. La dernière liste d'arguments est pour passer les valeurs dans le scriptblock de invoke-command. Param identique utilisé pour l'accepter à l'intérieur du bloc. Et enfin, il va commencer à démarrer la liste des arguments où vous voulez réellement passer –

0

Essayez celui-ci:

# Lets store each cmd parameter in an array 
$arguments = @() 
$arguments += "-clientId TX7283" 
$arguments += "-batch Batch82Y7" 
invoke-command -computername FRB-TER1 { 
    param (
     [string[]] 
     $receivedArguments 
    ) 

    # Start-Process now receives an array with arguments 
    Start-Process -FilePath "C:\Program Files (x86)\Acorne\LoadDen.exe" -ArgumemtList $receivedArguments 
    } -ArgumentList @(,$arguments) # Ensure that PS passes $arguments as array 
0

Pour passer une variable locale à un scriptblock exécuté à distance, vous pouvez également utiliser $Using:Varname (de Posh version 3.0 sur) . Voir l'aide de Invoke-Command:

> help Invoke-Command -Full |Select-String -Pattern '\$using' -Context 1,7 

 PS C:\> Invoke-Command -ComputerName Server01 -ScriptBlock {Get-EventLog 
> -LogName $Using:MWFO_Log -Newest 10} 

    This example shows how to include the values of local variables in a 
    command run on a remote computer. The command uses the Using scope 
    modifier to identify a local variable in a remote command. By default, all 
    variables are assumed to be defined in the remote session. The Using scope 
    modifier was introduced in Windows PowerShell 3.0. For more information 
    about the Using scope modifier, see about_Remote_Variables 
  • Si scriptblocks sont imbriquées, vous pouvez répéter le $using:varname Voir this reference

Donc, cela devrait fonctionner aussi (non testé)

$arguments = "-clientId TX7283 -batch Batch82Y7" 
Invoke-Command -computername FRB-TER1 {Start-Process -FilePath "C:\Program Files (x86)\Acorne\LoadDen.exe" $Using:arguments}