Previously the location the file was uploaded to was set internally and
used ${env:SYSTEMROOT}/Temp as the destination folder.
By default, in order to inject the required environment variables, the file
is 'dot sourced' by the 'execute_command' using the {{ .Vars }} variable.
Unfortunately the inclusion of the dollar in the path caused issues for
users connecting over ssh as the (typically bash) shell running the execute
command would try and interpret the dollar sign.
The change allows users to specify the location the file is uploaded to,
thereby allowing the user to specify a custom 'execute_command' that
escapes any dollar signs that could be present in the path.
If not set the upload path now defaults to using C:/Windows/Temp as the
upload folder.
* Wrap funcs to flatten and upload env vars with new func prepareEnvVars.
While the wrapped funcs could be combined, keeping them separate
simplifies testing.
* Configure/refactor std and elevated PS to use new funcs to prepare,
upload and dot source env vars.
* Dot sourcing the env vars in this way avoids the need to embed them
directly in the command string. This avoids the need to escape the env
vars to ensure the command string is correctly parsed.
* Characters within the env vars that are special to PS (such as $'s
and backticks) will still need to be escaped to allow them to be
correctly interpreted by PS.
* The std and elevated PS commands now inject env vars into the remote
env via the same mechanism. This ensures consistent behaviour across the
two command types.
Fixes#5471
Revert so that we can merge a different branch that's had more recent work instead
This reverts commit ba518637d4, reversing
changes made to e56849c605.
* Wrap funcs to flatten and upload env vars with new func prepareEnvVars.
While the wrapped funcs could be combined, keeping them separate
simplifies testing.
* Configure/refactor std and elevated PS to use new funcs to prepare,
upload and dot source env vars.
* Dot sourcing the env vars in this way avoids the need to embed them
directly in the command string. This avoids the need to escape the env
vars to ensure the command string is correctly parsed.
* Characters within the env vars that are special to PS (such as $'s
and backticks) will still need to be escaped to allow them to be
correctly interpreted by PS.
* The std and elevated PS commands now inject env vars into the remote
env via the same mechanism. This ensures consistent behaviour across the
two command types.
Fixes#5471
* Setting $ProgressPreference to SilentlyContinue makes no difference
when -EncodedCommand is used - any output to the progress stream
still appears on stderr.
* Delete file containing encode/decode functions since we no longer
need them.
* Fixes leak of output on progress streams for both normal and elevated
commands.
* Since we no longer base64 encode, ensure any characters special to XML
are correctly escaped in the elevated command. This ensures correct
parsing once the command is wrapped within the elevatedTemplates XML
based Task Scheduler definition.
Fixes#4322
Fix a bug in the size of string that was returned when decoding a base64 string
Added tests around encoding and decoding powershell scripts. Used [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes('powershell commands')) | clip to generate what base 64 strings should look like