{"_id":"powershell-utils@0.2.1","bugs":{"url":"https://github.com/sindresorhus/powershell-utils/issues"},"dist":{"shasum":"0853016f5b3c12d52b9571c8fe8059677d9ddbe2","tarball":"http://registry-npm.ywwl.com/powershell-utils/download/powershell-utils-0.2.1.tgz","fileCount":5,"integrity":"sha512-C+y9x90UElAddDZmV4qOx9W53B61PO7cIqWz2dQsWlwswuq4mr8NEwytdGKboYbQlGZ3awrkTeNvcZiZNHnQ8A==","signatures":[{"sig":"MEUCIFbVCuucJ5Agx7gkQzn5ZepjjDmsLYwrayClKw11WN5bAiEAhkuHNzgF1nuOoOCOHxnljXjZIm9NKZrFrxc8Os/99TU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIC08h+kYSEZBquz4yYZkiC1n+7qf1TPYjZ0uxE1SSiYBAiABq3vZmyOqrFe+Ms1WT1jC2fao8TzDRyW+7uZeSL6GFg=="}],"unpackedSize":14435,"size":4144,"noattachment":false,"key":"/powershell-utils/-/powershell-utils-0.2.1.tgz"},"name":"powershell-utils","type":"module","types":"./index.d.ts","author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"engines":{"node":">=20"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"8f8bcdc355afc10d0aea7337fbf1fc140b837bc1","license":"MIT","scripts":{"test":"xo && ava && tsc index.d.ts --skipLibCheck"},"version":"0.2.1","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"homepage":"https://github.com/sindresorhus/powershell-utils#readme","keywords":["powershell","windows","execute","command","shell","console","terminal","cli","spawn","exec","utilities"],"repository":{"url":"git+https://github.com/sindresorhus/powershell-utils.git","type":"git"},"_npmVersion":"12.0.1","description":"Utilities for executing PowerShell commands","directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"sideEffects":false,"_nodeVersion":"22.23.1","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.59.0","ava":"^6.4.1","typescript":"^5.9.3"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/powershell-utils_0.2.1_1788008294847_0.15071595713683328"},"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 all options except `shell` in Node.js [`child_process.execFile()`](https://nodejs.org/api/child_process.html#child_processexecfilefile-args-options-callback) are supported. PowerShell is always executed directly to prevent shell injection.\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> [!IMPORTANT]\n> This makes a value safe as a PowerShell string literal, not as an argument to a native program. PowerShell removes the outer quotes before passing a value onwards, and the receiving process then re-splits it under its own command-line rules, where spaces and double quotes are delimiters. For example, `Start-Process -ArgumentList` receives `'a b'` as two arguments rather than one.\n>\n> Escaping also does not make an untrusted value safe to use as the program that `Start-Process` runs. Validate such values against an allowlist.\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 all options except `shell` in Node.js [`child_process.execFileSync()`](https://nodejs.org/api/child_process.html#child_processexecfilesyncfile-args-options) are supported. PowerShell is always executed directly to prevent shell injection.\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","publish_time":1788008294937,"_cnpm_publish_time":1788008294937,"dist-tags":{"latest":"0.2.1"}}