0

I am trying to pass value for argument in below command script called install.ps1. I execute it by ./install.ps1 HD1

invoke-command -Session $session -ScriptBlock {G:\usr\sap\$($args[0])\hdbclient\hdbuserstore.exe list}

but it gave an error to me that

The term 'G:\usr\sap\$($args[0])\hdbclient\hdbuserstore.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. + CategoryInfo : ObjectNotFound: (G:\usr\sap\$($a...dbuserstore.exe:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException + PSComputerName : hostname

2
  • What ($args[0]) is supposed to contain? It is passed as string literal, not expanded variable, so the OS is looking for wrong path. Commented May 14, 2018 at 5:52
  • It supposed to accept HD1 value which I am passing as an argument with install.ps1. Commented May 14, 2018 at 6:06

1 Answer 1

2

You are not using the -Argumentlist parameter on Invoke-Command. Let me show an example below. Use the Param method inside the scriptblock if you want to use custom variable names.

$Directory = "HD1"
$Scriptblock = {
    param($Var1)
    G:\usr\sap\$Var1\hdbclient\hdbuserstore.exe list
}
invoke-command -Session $session -ScriptBlock $Scriptblock -ArgumentList $Directory
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.