Question: Running Powershell script remotely with custom parameters

Hello Guys/Girls, I am trying to run this script remotely from a Windows 2008 R2

SCRIPT_NAME: runJMXClient.ps1

OS : Windows (PowerShell version)

DESC : Websphere JMX Client

This script get MBean metric from WebSphere using JMX, the metric to query

are read from the configuration file, see monitor.properties

Variable WASADM_HOME must be defined in environment

The configuration file must be exist in $WASADM_HOME\etc

Example of usage:

runJMXClient.ps1 monitor.properties

DATE : $Date$

VERSION : $Rev$

AUTHOR : $Author$

OBS :

NOTE : See also monitor.properties

For Linux/Unix use the wrapper script runJMXClient.sh

Param(
[string]$f
)

$WASADM_HOME= $Env:WASADM_HOME
$JAVA_HOME= “$Env:WASADM_HOME/bin/java/win”

$C1 = “$WASADM_HOME/lib/8.0.0/runtimes”
$C2 = “$WASADM_HOME/lib”

$CLASSPATH=
$CLASSPATH= “$C1/com.ibm.jaxws.thinclient_8.0.0.jar”
$CLASSPATH= “$CLASSPATH;$C1/com.ibm.ws.admin.client_8.0.0.jar”
$CLASSPATH= “$CLASSPATH;$C1/com.ibm.ws.ejb.thinclient_8.0.0.jar”
$CLASSPATH= “$CLASSPATH;$C1/com.ibm.ws.orb_8.0.0.jar”
$CLASSPATH= “$CLASSPATH;$C2”

Logging

$L=“-J-Dsun.rmi.level=FINEST -J-Djava.util.logging.config.file=$WASADM_HOME/etc/logging.properties”

$_file = $args
$cmd = “$JAVA_HOME/bin/java.exe -cp “”$CLASSPATH”" JMXClient $WASADM_HOME/etc/$f 2> $WASADM_HOME/log/runJMXClient.err"

Invoke-Expression $cmd -ErrorAction SilentlyContinue

As you can see I have the -F parameter but when I try to run it: Invoke-Command -ComputerName mycompname -FilePath \mycompnameD$\Appls\IBM\was\scripts\runJMXClient.ps1 -f value it doesn’t work.

Do you know how can I run the script remotely and pass the value I need?

Look at the -Argument parameter of Invoke-Command. There’s a defined mechanism to do what you’re after.