Forum Discussion
John_Dodo
Oct 19, 2022Copper Contributor
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 ...
- Oct 19, 2022
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
LainRobertson
Oct 19, 2022Silver Contributor
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
John_Dodo
Oct 19, 2022Copper Contributor
LainRobertson thank you so much ! It works thanks to you.
Next step is to get rid of psexec but for the moment it will help a lot.