{"name":"powershell-utils","version":"0.1.0","keywords":["powershell","windows","execute","command","shell","console","terminal","cli","spawn","exec","utilities"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"powershell-utils@0.1.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/powershell-utils#readme","bugs":{"url":"https://github.com/sindresorhus/powershell-utils/issues"},"dist":{"shasum":"5a42c9a824fb4f2f251ccb41aaae73314f5d6ac2","tarball":"http://registry-npm.ywwl.com/powershell-utils/download/powershell-utils-0.1.0.tgz","fileCount":5,"integrity":"sha512-dM0jVuXJPsDN6DvRpea484tCUaMiXWjuCn++HGTqUWzGDjv5tZkEZldAJ/UMlqRYGFrD/etByo4/xOuC/snX2A==","signatures":[{"sig":"MEUCIQDJNyNhovKY6yIoG6vV/qk6tH+bRQzdvdAd73Tl58SztgIgR25zFUuUv2uHazOrHGQ2kwS1zgnRMNvDoul9CoZkMKg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":9813,"size":3230,"noattachment":false,"key":"/powershell-utils/-/powershell-utils-0.1.0.tgz"},"type":"module","types":"./index.d.ts","engines":{"node":">=20"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"66187bc2c4a73cf1d85d92836ae6ab70e5c5eb9c","scripts":{"test":"xo && ava && tsc index.d.ts --skipLibCheck"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/powershell-utils.git","type":"git"},"_npmVersion":"11.6.1","description":"Utilities for executing PowerShell commands","directories":{},"sideEffects":false,"_nodeVersion":"20.19.5","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.59.0","ava":"^6.4.1","typescript":"^5.9.3"},"_npmOperationalInternal":{"tmp":"tmp/powershell-utils_0.1.0_1763194224198_0.8989235522659442","host":"s3://npm-registry-packages-npm-production"},"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","publish_time":1763194224411,"_cnpm_publish_time":1763194224411,"dist-tags":{"latest":"0.2.1"}}