Forum Discussion

John_Dodo's avatar
John_Dodo
Copper Contributor
Oct 19, 2022
Solved

string not properly interpreted when calling a script

 Hello,     in a script I have to call psexec to execute a remote script on a remote target (I could probably do an invoke... but I didn't manage to make this work yet so for the moment I need to ...
  • LainRobertson's avatar
    Oct 19, 2022

    John_Dodo 

     

    I'm a little unclear on what the command should look like but the following three variables will be resolved within your existing script block, i.e. on the host doing the calling:

     

    • $targetserver
    • $local_rep
    • $filename

     

    The fourth "variable", $pathtomyscript, will not be resolved caller-side. Instead, it will be passed into remotely-initiated PowerShell call where that remote PowerShell session will try to parse $pathtomyscript - which will fail (or more correctly, it will resolve to $null.)

     

    If you have defined $pathtomyscript within the caller-side script block then there's multiple ways of dealing with the string parsing, but perhaps the closest to what you already have would look like this:

     

    .\psexec.exe "\\$targetserver" -accepteula powershell "`"$pathtomyscript$local_rep\$filename`"" "C:\_Scripts\_Logs"

     

    Cheers,

    Lain

Resources