Skip to main content

Converts the output of a powershell (Get-...)/wmic command to a dict

pip install wmicprocsdict

Tested against Windows 10 / Python 3.11 / Anaconda

Args:
    cmd (str): The command to execute.
    convert_dtypes_with_ast (bool, optional): Whether to convert column data types to their appropriate types using the ast module. Defaults to True.
    format_powershell (bool, optional): Format to: f'powershell "{cmd} | Format-Table *"'. Defaults to False.
    cols (int): Number of columns for the console. Defaults to 9999999.
    lines (int): Number of lines for the console. Defaults to 1.

Returns:
    dict: A dictionary representing the command output.

Example:

from wmicprocsdict import get_dict_from_command

d1 = get_dict_from_command(
    cmd="Get-Process",
    convert_dtypes_with_ast=True,
    format_powershell=True,
    cols=9999999,
    lines=1,
)
d2 = get_dict_from_command(
    cmd=f'powershell "Get-Process | Format-Table *"',
    convert_dtypes_with_ast=True,
    format_powershell=False,
    cols=9999999,
    lines=1,
)
e1 = get_dict_from_command(
    cmd="wmic process",
    convert_dtypes_with_ast=True,
    format_powershell=False,
    cols=9999999,
    lines=1,
)

d3 = get_dict_from_command(
    cmd="Get-Service",
    convert_dtypes_with_ast=True,
    format_powershell=True,
    cols=9999999,
    lines=1,
)

d4 = get_dict_from_command(
    cmd=f'powershell "Get-Service | Format-Table *"',
    convert_dtypes_with_ast=True,
    format_powershell=False,
    cols=9999999,
    lines=1,
)
print(d1)
print(d2)
print(e1)
print(d3)
print(d4)

# {0: {'Id': 56, 'PriorityClass': 'Normal', 'FileVersion': (6, 6, 0, 0), 'HandleCount': 430, 'WorkingSet': 32923648, 'PagedMemorySize': 38731776, 'PrivateMemorySize': 38731776, 'Virt...
# {0: {'Id': 56, 'PriorityClass': 'Normal', 'FileVersion': (6, 6, 0, 0), 'HandleCount': 430, 'WorkingSet': 32923648, 'PagedMemorySize': 38731776, 'PrivateMemorySize': 38731776, 'Virt...
# {0: {'CommandLine': '', 'CreationClassName': 'Win32_Process', 'CreationDate': '20240325180030.969217-180', 'CSCreationClassName': 'Win32_ComputerSystem', 'CSName': '...
# {0: {'RequiredServices': {}, 'CanPauseAndContinue': False, 'CanShutdown': False, 'CanStop': False, 'DisplayName': 'Agent Activation Runtime_c5578', 'DependentServices': {}, 'Machin...
# {0: {'RequiredServices': {}, 'CanPauseAndContinue': False, 'CanShutdown': False, 'CanStop': False, 'DisplayName': 'Agent Activation Runtime_c5578', 'DependentServices': {}, 'Machin...

Release files for wmicprocsdict 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wmicprocsdict 0.10
File Size Uploaded
wmicprocsdict-0.10.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wmicprocsdict 0.10
File Interpreter ABI Platform
wmicprocsdict-0.10-py3-none-any.whl Python 3 none any Details

Total release size: 11.8 kB

Release files / wmicprocsdict-0.10.tar.gz

Download URL wmicprocsdict-0.10.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
81d93f7db35a3e4a27891c225e502a878c348d5901ad78432ba8dc71d348440c
BLAKE2b-256 checksum
How to use checksums
b84e3fe4ea879dfe32c16833f6525b952eb7f6e462b93f1a7df2497ef38f7330
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / wmicprocsdict-0.10-py3-none-any.whl

Download URL wmicprocsdict-0.10-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb5b654da797f91494390d113e464be2fab1b1a45bc9d7e398b12e2209afa93a
BLAKE2b-256 checksum
How to use checksums
0df02f10aae25cc92b2150ee6c76439004c871c0df6c233fe2e0f9ee419fe11b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page