npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

powershell-utils

v0.1.0

Published

Utilities for executing PowerShell commands

Readme

powershell-utils

Utilities for executing PowerShell commands

Install

npm install powershell-utils

Usage

import {executePowerShell, powerShellPath} from 'powershell-utils';

// Execute a PowerShell command
const {stdout} = await executePowerShell('Get-Process');
console.log(stdout);

// Get PowerShell path
console.log(powerShellPath());
//=> 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'

API

powerShellPath()

Returns: string

Get the PowerShell executable path on Windows.

import {powerShellPath} from 'powershell-utils';

const psPath = powerShellPath();
//=> 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'

canAccessPowerShell()

Returns: Promise<boolean>

Check if PowerShell is accessible on Windows.

This checks if the PowerShell executable exists and has execute permissions. Useful for detecting restricted environments where PowerShell may be disabled by administrators.

import {canAccessPowerShell} from 'powershell-utils';

if (await canAccessPowerShell()) {
	console.log('PowerShell is available');
} else {
	console.log('PowerShell is not accessible');
}

executePowerShell(command, options?)

Returns: Promise<{stdout: string, stderr: string}>

Execute a PowerShell command.

import {executePowerShell} from 'powershell-utils';

// Execute a PowerShell command
const {stdout} = await executePowerShell('Get-Process');
console.log(stdout);

command

Type: string

The PowerShell command to execute.

options

Type: object

The below option and also all options in Node.js child_process.execFile() are supported.

powerShellPath

Type: string
Default: powerShellPath()

Path to PowerShell executable. Useful when calling from WSL or when PowerShell is in a non-standard location.

encoding

Type: string
Default: 'utf8'

Character encoding for stdout and stderr.

executePowerShell.argumentsPrefix

Type: string[]

Standard PowerShell arguments that prefix the encoded command.

Use these when manually building PowerShell execution arguments for spawn(), execFile(), etc.

import {executePowerShell} from 'powershell-utils';

const arguments_ = [...executePowerShell.argumentsPrefix, encodedCommand];
childProcess.spawn(powerShellPath(), arguments_);

executePowerShell.encodeCommand(command)

Returns: string

Encode a PowerShell command as Base64 UTF-16LE.

This encoding prevents shell escaping issues and ensures complex commands with special characters are executed reliably.

command

Type: string

The PowerShell command to encode.

import {executePowerShell} from 'powershell-utils';

const encoded = executePowerShell.encodeCommand('Get-Process');

executePowerShell.escapeArgument(value)

Returns: string

Escape a string argument for use in PowerShell single-quoted strings.

value

Type: unknown

The value to escape.

import {executePowerShell} from 'powershell-utils';

const escaped = executePowerShell.escapeArgument("it's a test");
//=> "'it''s a test'"

// Use in command building
const command = `Start-Process ${executePowerShell.escapeArgument(appName)}`;