MSdeploy.exe how to use special character in setparam value - iis

"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
We would like to use -setParam:"TestParam"="hello&1", but PowerShell sees the & character as the call operator instead of a literal. How can we change this to use the & as literal in the setparam value?

Related

Why don't substrings work with command line arguments?

In a Windows batch file, the following will work to extract all of %1 except the last 4 characters:
set foo=%1
set x=%foo:~,-4%
But this will not work:
set x=%1:~,-4%
Why is this?
The Windows command processor cmd.exe supports string substitutions only with environment variables (and with dynamic variables), but not with batch file arguments (or with loop variables).
foo is an environment variable of which value is referenced with immediate expansion using %foo% and with delayed expansion with !foo!. String substitutions are supported for environment variables as described by the help output on running set /? in a command prompt window. The Windows command processor cmd.exe supports string substitutions on environment (and dynamic) variable expansions everywhere in a command line.
For more details see How does the Windows Command Interpreter (CMD.EXE) parse scripts?
For an explanation of the difference between environment and dynamic variables read the long answer on Difference between Dynamic Environment Variables and Normal Environment Variables in CMD.
%1 references an argument passed to the batch file. The help output on running call /? in a command prompt window explains how arguments can be referenced in a batch file and which modifiers are supported by the Windows command processor. String substitutions are not supported by cmd.exe on argument strings.
For completeness the help output on running for /? explains how a loop variable can be referenced inside the body of a loop and which modifiers are available (the same as for argument references). String substitutions are not support for loop variables.

Howto: Escape $(var) in Azure DevOps YAML

variables:
buildSelected: '1.0.0.1234'
steps:
- powershell: |
Write-Host "Build Selected $(buildSelected)"
Write-Host "Escaped '$(buildSelected)'"
displayName: "Escape variable"
I would like the value 1.0.0.1234 & '$(buildSelected)' to be printed instead of what it's printing now:
Build Selected 1.0.0.1234
Escaped '1.0.0.1234'
Sorry but I'm afraid Azure Devops doesn't provide the feature to escape a pipeline variable. If the variable is used in this format $(var), it will always be replaced with its value when using Write-Host to output it.
As I know in Powershell syntax, only the ` can be used to escape variables. See:
Write-Host "Build Selected `$`(buildSelected)"
Its output : Build Selected $(buildSelected)
Not sure if it's what you need, but escaping pipeline variables with complete $(var) is not supported. Azure Devops will always replace it with its value if it matches the $(var) format.
I had the same problem but in bash and solved it by adding the invisible character named "ZERO WIDTH SPACE" between "$" and "(". This way I can print out "$(Build.SourceVersion)" without it being replaced with the actual value.
I copied the character from https://invisible-characters.com/
---
trigger: none
steps:
- script: |
echo "$​(Build.SourceVersion): $(Build.SourceVersion)"
displayName: Test Pipeline Variable Escaping

Argument escaping not interpreted correctly when running node.js script from Windows PowerShell

Given the following script:
const yargs = require('yargs');
const argv =
yargs
.usage('Usage: $0 [--whatIf]')
.alias('d', 'directory')
.alias('wi', 'whatIf')
.nargs('d', 1)
.describe('d', 'alphabetize this directory')
.describe('whatIf', 'show what would happen if run')
.demandOption(['d'])
.argv;
console.log(argv.directory);
If I invoke the script from Windows PowerShell like so: node .\alphabetizer.js -d 'l:\my folder\Files - Some Files In Here\' --whatIf I get the output l:\my folder\Files - Some Files In Here\" --whatIf where I would expect just l:\my folder\Files - Some Files In Here\. It works OK with folder names that require no escaping, but it seems to get confused by the escaping.
If I examine process.argv, I can see the same escaping issue.
I have noticed that if I remove the trailing slash it will work. However, this still points to the node script not handling the input properly, because this should not be necessary with string set off by single quotes.
Is there a way to make this work?
Both Windows PowerShell (powershell.exe) and PowerShell [Core] v6+ (pwsh) are fundamentally broken with respect to quoting arguments for external programs properly - see this answer for background info.
Generally, PowerShell on Windows has to perform re-quoting behind the scenes in order to ensure that just "..."-quoting is used, given that external programs can't be assumed to understand '...'-quoting too when parsing their command line (which on Windows every program has to do itself).
Windows PowerShell is more broken with respect to arguments that end in \ and have embedded spaces, re-quoting them improperly; e.g.:
PS> foo.exe 'c:\foo \' bar
is translated into the following command line behind the scenes:
foo.exe "c:\ foo \" bar
This is broken, in that most applications - including PowerShell's own CLI - sensibly assume that the \" is an escaped " char. to be taken verbatim, thinking that the argument continues with  bar and then implicitly ends, despite the formal lack of a closing ".
PowerShell [Core] v6+ more sensibly translates the above to foo.exe "c:\foo \\" bar, where the \\ is interpreted as an escaped \, and the following " again has syntactic function.
If you're stuck with Windows PowerShell, your only choices are:
either: if possible, leave off the trailing \
otherwise: manually double it (\\), but only do so if the argument also contains spaces (otherwise, the \\ will be retained as-is, though in the case of filesystem paths that is usually benign).

How to uglify a javascript file from VBA?

I installed node.js in my Windows environment, and also uglify-js
I created a sequence of uglifyjs commands and saved it in a file called uglify.js
uglifyjs K:\Temp\jsfiles\jsslashcharts.js -c -m -o K:\Temp\jsfiles\jsslashcharts.js
uglifyjs K:\Temp\jsfiles\jsslashdates.js -c -m -o K:\Temp\jsfiles\jsslashdates.js
How can I run this in node.js using VBA?
The closest thing I found on Stack Overflow is Run Node.js using VBA
So I tried (unsuccessfully)
Shell "C:\Program Files\nodejs\node.exe uglify.js", vbMaximizedFocus
The exe path contains spaces, so that will need to be double quoted, as "C:\Program Files\nodejs\node.exe" within the literal containing the command. Same goes for any arguments containing spaces.
Shell """C:\Program Files\nodejs\node.exe"" uglify.js", vbMaximizedFocus
Take a look at Quotation marks in string expressions (my emphasis)
You should include double quotation marks within the criteria argument in such a way so that when the value of the variable is evaluated, it will be enclosed within the quotation marks. Within a string, you must use two sets of double quotation marks to represent a single set of double quotation marks.

How to create a triple nested command line string for Shell function in VBA?

I need to create a VBA Macro in Excel.
The task is that when a button is clicked a command will be executed in cmd.
The command to be executed is rfrompcb and it takes the path of a file as argument so there is the first level string which wraps the path up as it contains spaces. As this command is to be executed in cmd there is the second level string, which is the argument for cmd command, i.e. cmd /c "rfrompcb ""file_path""" (I hope I have got this one right). Then since it is to be called by Shell in VBA there is the third level string which wraps the cmd command and serves as the argument for Shell.
My question is: How many double quotation marks should there be? I am quite confused about what the final command line string would look like. Can anyone show me how to construct such string? Or is there another way to do it which involves less string nesting?
Thanks.
You would only need to quote file_path, for example:
shell environ$("COMSPEC") & " /c dir ""c:\program files\"" /b"
environ$("COMSPEC") just returns the full path for cmd.exe.
If the executable path you wish to run does not need to be quoted then to pass it an argument that does need to be quoted:
Shell Environ$("COMSPEC") & " /c rfrompcb ""file path"""
If the exe path does need to be quoted you need to wrap it all in another pair of quotes so it looks like:
cmd.exe /c ""c:\path to\rfrompcb" "file path""
Which can be done:
Shell Environ$("COMSPEC") & " /c """"c:\path to\rfrompcb"" ""file path"""""

Resources