Skip to content

Commit 09318fa

Browse files
Added support for usage of reserved powershell variables in commands [$null, $true, $false]
1 parent 1175686 commit 09318fa

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ Three sets of init commands are availiable as of version `1.1.0`:
5757
### <a id="history"></a>History
5858

5959
```
60+
v1.1.2 - 2022-07-06
61+
- Added support for usage of reserved powershell variables in commands [$null, $true, $false]
62+
6063
v1.1.1 - 2020-12-07
6164
- Fixed bug import of custom commands if provided for certificate based auth
6265

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "powershell-command-executor",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Provides a registry and gateway for execution powershell commands through long-lived established remote PSSessions via a stateful-process-command-proxy pool of powershell processes",
55
"main": "psCommandService.js",
66
"directories": {

psCommandService.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ module.exports = PSCommandService;
33
var Promise = require('promise');
44
var Mustache = require('mustache');
55

6+
/**
7+
* Reserved variables in Powershell to allow as arguments
8+
* @see https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.2
9+
*/
10+
const reservedVariableNames = ['$null', '$false', '$true'];
11+
612
/**
713
* PSCommandService
814
*
@@ -366,6 +372,9 @@ PSCommandService.prototype._sanitize = function(toSanitize,isQuoted) {
366372
if (isQuoted) {
367373
toSanitize = toSanitize.replace(/(['])/g, "'$1");
368374

375+
// skip if this is reserved variable name
376+
} else if (reservedVariableNames.includes(toSanitize)) {
377+
// skip it
369378
// if not quoted, stop $ and |
370379
} else {
371380
toSanitize = toSanitize.replace(/([;\$\|\(\)\{\}\[\]\\])/g, "`$1");

0 commit comments

Comments
 (0)