{"_id":"powershell-utils","_rev":"4308679","name":"powershell-utils","description":"Utilities for executing PowerShell commands","dist-tags":{"latest":"0.2.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2026-04-07T21:44:10.000Z","created":"2025-11-15T08:10:24.411Z","0.2.0":"2026-01-25T03:39:53.218Z","0.1.0":"2025-11-15T08:10:24.411Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/powershell-utils.git"},"versions":{"0.2.0":{"name":"powershell-utils","version":"0.2.0","description":"Utilities for executing PowerShell commands","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/powershell-utils.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=20"},"scripts":{"test":"xo && ava && tsc index.d.ts --skipLibCheck"},"keywords":["powershell","windows","execute","command","shell","console","terminal","cli","spawn","exec","utilities"],"devDependencies":{"ava":"^6.4.1","typescript":"^5.9.3","xo":"^0.59.0"},"gitHead":"647dbfb616e3817db95898ab52e1cf1e6931e24d","types":"./index.d.ts","_id":"powershell-utils@0.2.0","bugs":{"url":"https://github.com/sindresorhus/powershell-utils/issues"},"homepage":"https://github.com/sindresorhus/powershell-utils#readme","_nodeVersion":"25.3.0","_npmVersion":"11.7.0","dist":{"shasum":"bb075dcadc1564f3bd80fddda4f0a481ccbdcf36","size":3554,"noattachment":false,"key":"/powershell-utils/-/powershell-utils-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/powershell-utils/download/powershell-utils-0.2.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/powershell-utils_0.2.0_1769312393060_0.6824654007037241"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2026-01-25T03:39:53.218Z","publish_time":1769312393218,"_source_registry_name":"default","_cnpm_publish_time":1769312393218},"0.1.0":{"name":"powershell-utils","version":"0.1.0","description":"Utilities for executing PowerShell commands","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/powershell-utils.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=20"},"scripts":{"test":"xo && ava && tsc index.d.ts --skipLibCheck"},"keywords":["powershell","windows","execute","command","shell","console","terminal","cli","spawn","exec","utilities"],"devDependencies":{"ava":"^6.4.1","typescript":"^5.9.3","xo":"^0.59.0"},"gitHead":"66187bc2c4a73cf1d85d92836ae6ab70e5c5eb9c","types":"./index.d.ts","_id":"powershell-utils@0.1.0","bugs":{"url":"https://github.com/sindresorhus/powershell-utils/issues"},"homepage":"https://github.com/sindresorhus/powershell-utils#readme","_nodeVersion":"20.19.5","_npmVersion":"11.6.1","dist":{"shasum":"5a42c9a824fb4f2f251ccb41aaae73314f5d6ac2","size":3230,"noattachment":false,"key":"/powershell-utils/-/powershell-utils-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/powershell-utils/download/powershell-utils-0.1.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/powershell-utils_0.1.0_1763194224198_0.8989235522659442"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-11-15T08:10:24.411Z","publish_time":1763194224411,"_source_registry_name":"default","_cnpm_publish_time":1763194224411}},"readme":"# powershell-utils\n\n> Utilities for executing PowerShell commands\n\n## Install\n\n```sh\nnpm install powershell-utils\n```\n\n## Usage\n\n```js\nimport {executePowerShell, powerShellPath} from 'powershell-utils';\n\nconst {stdout} = await executePowerShell('Get-Process');\nconsole.log(stdout);\n\nconsole.log(powerShellPath());\n//=> 'C:\\\\Windows\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe'\n```\n\n## API\n\n### powerShellPath()\n\nReturns: `string`\n\nGet the PowerShell executable path on Windows.\n\n```js\nimport {powerShellPath} from 'powershell-utils';\n\nconst psPath = powerShellPath();\n//=> 'C:\\\\Windows\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe'\n```\n\n### canAccessPowerShell()\n\nReturns: `Promise<boolean>`\n\nCheck if PowerShell is accessible on Windows.\n\nThis checks if the PowerShell executable exists and has execute permissions. Useful for detecting restricted environments where PowerShell may be disabled by administrators.\n\n```js\nimport {canAccessPowerShell} from 'powershell-utils';\n\nif (await canAccessPowerShell()) {\n\tconsole.log('PowerShell is available');\n} else {\n\tconsole.log('PowerShell is not accessible');\n}\n```\n\n### executePowerShell(command, options?)\n\nReturns: `Promise<{stdout: string, stderr: string}>`\n\nExecute a PowerShell command.\n\n```js\nimport {executePowerShell} from 'powershell-utils';\n\nconst {stdout} = await executePowerShell('Get-Process');\nconsole.log(stdout);\n```\n\n#### command\n\nType: `string`\n\nThe PowerShell command to execute.\n\n#### options\n\nType: `object`\n\nThe below option and also all options in Node.js [`child_process.execFile()`](https://nodejs.org/api/child_process.html#child_processexecfilefile-args-options-callback) are supported.\n\n##### powerShellPath\n\nType: `string`\\\nDefault: `powerShellPath()`\n\nPath to PowerShell executable. Useful when calling from WSL or when PowerShell is in a non-standard location.\n\n##### encoding\n\nType: `string`\\\nDefault: `'utf8'`\n\nCharacter encoding for stdout and stderr.\n\n### executePowerShell.argumentsPrefix\n\nType: `string[]`\n\nStandard PowerShell arguments that prefix the encoded command: `['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-EncodedCommand']`\n\nExposed for debugging or for advanced use cases where you need to customize the arguments. For most cases, use `createArguments()` instead.\n\n### executePowerShell.encodeCommand(command)\n\nReturns: `string`\n\nEncode a PowerShell command as Base64 UTF-16LE.\n\nThis encoding prevents shell escaping issues and ensures complex commands with special characters are executed reliably.\n\n#### command\n\nType: `string`\n\nThe PowerShell command to encode.\n\n```js\nimport {executePowerShell} from 'powershell-utils';\n\nconst encoded = executePowerShell.encodeCommand('Get-Process');\n```\n\n### executePowerShell.escapeArgument(value)\n\nReturns: `string`\n\nEscape a string argument for use in PowerShell single-quoted strings.\n\n#### value\n\nType: `unknown`\n\nThe value to escape.\n\n```js\nimport {executePowerShell} from 'powershell-utils';\n\nconst escaped = executePowerShell.escapeArgument(\"it's a test\");\n//=> \"'it''s a test'\"\n\n// Use in command building\nconst command = `Start-Process ${executePowerShell.escapeArgument(appName)}`;\n```\n\n### executePowerShell.createArguments(command)\n\nReturns: `string[]`\n\nCreate the full arguments array for PowerShell execution.\n\nCombines `argumentsPrefix` with the encoded command. Useful when using `spawn()`, `execFile()`, or other process execution methods.\n\n#### command\n\nType: `string`\n\nThe PowerShell command.\n\n```js\nimport {spawn} from 'node:child_process';\nimport {powerShellPath, executePowerShell} from 'powershell-utils';\n\nconst args = executePowerShell.createArguments('Get-Process');\nspawn(powerShellPath(), args);\n```\n\n### executePowerShellSync(command, options?)\n\nReturns: `string`\n\nExecute a PowerShell command synchronously.\n\n```js\nimport {executePowerShellSync} from 'powershell-utils';\n\nconst stdout = executePowerShellSync('Get-Process');\nconsole.log(stdout);\n```\n\n#### command\n\nType: `string`\n\nThe PowerShell command to execute.\n\n#### options\n\nType: `object`\n\nThe below option and also all options in Node.js [`child_process.execFileSync()`](https://nodejs.org/api/child_process.html#child_processexecfilesyncfile-args-options) are supported.\n\n##### powerShellPath\n\nType: `string`\\\nDefault: `powerShellPath()`\n\nPath to PowerShell executable.\n\n##### encoding\n\nType: `string`\\\nDefault: `'utf8'`\n\nCharacter encoding for the output.\n","_attachments":{},"homepage":"https://github.com/sindresorhus/powershell-utils#readme","bugs":{"url":"https://github.com/sindresorhus/powershell-utils/issues"},"license":"MIT"}