Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure pypsrp for settings like WSManStackVersion #172

Open
mabangde opened this issue May 4, 2023 · 1 comment
Open

configure pypsrp for settings like WSManStackVersion #172

mabangde opened this issue May 4, 2023 · 1 comment

Comments

@mabangde
Copy link

mabangde commented May 4, 2023

How to configure pypsrp for settings like WSManStackVersion in PowerShell, for example, the following configuration?
image

$secureString = ConvertTo-SecureString -String "Pwd" -AsPlainText -Force $UserCredential = New-Object System.Management.Automation.PSCredential -ArgumentList "lab\john", $secureString $version = New-Object -TypeName System.Version -ArgumentList "2.0" $mytable = $PSversionTable $mytable["WSManStackVersion"] = $version $sessionOption = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck -ApplicationArguments @{PSversionTable=$mytable}

@jborean93
Copy link
Owner

jborean93 commented May 8, 2023

I'm not sure how you would configure that normally but the same command you've written in PowerShell would look like something like this in Python

from pypsrp.powershell import PowerShell, RunspacePool
from pypsrp.wsman import WSMan

with WSMan(...) as wsman:
    pool = RunspacePool(wsman)
    pool.open({"PSVersionTable": {"WSManStackVersion": "2.0"}})
    with pool:
        ps = PowerShell(pool)
        ...

This may or may not work as the version is just a string here and not a Version object. It can technically be done to create the required type but it's quite complex.

The newer psrp namespace (which is part of the 1.0.0b1 release) makes things a bit easier than before to do what you want.

import psrp
import psrpcore.types

wsman_conn = psrp.WSManInfo("hostname", ...)
app_args = {
    "PSVersionTable": {
        "WSManStackVersion": psrpcore.types.PSVersion("2.0"),
        ... # Whatever else you need to define.
    }
}

with psrp.SyncRunspacePool(wsman_conn, application_arguments=app_args) as rp:
    ps = psrp.SyncPowerShell(rp)
    ps.add_script("$PSVersionTable")
    output = ps.invoke()

    print(output)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants