0
votes

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

1
What ($args[0]) is supposed to contain? It is passed as string literal, not expanded variable, so the OS is looking for wrong path.vonPryz
It supposed to accept HD1 value which I am passing as an argument with install.ps1.hans

1 Answers

2
votes

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