Forum Discussion
string not properly interpreted when calling a script
- 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
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_DodoOct 19, 2022Brass 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.