Example #1
0
    def test_sanitise_clixml_with_no_errors(self):
        clixml_path = os.path.join(os.path.dirname(__file__), "data",
                                   "test_sanitise_clixml_with_no_errors.xml")
        with open(clixml_path, "r") as fd:
            clixml = fd.read()

        expected = ""

        actual = Client.sanitise_clixml(clixml)
        assert actual == expected
Example #2
0
    def test_sanitise_clixml_with_error(self):
        clixml_path = os.path.join(os.path.dirname(__file__), 'data',
                                   'test_sanitise_clixml_with_error.xml')
        with open(clixml_path, 'r') as fd:
            clixml = fd.read()

        expected = "fake : The term 'fake' is not recognized as the name of a cmdlet, function, script file, or operable program. Check \r\n" \
                   "the spelling of the name, or if a path was included, verify that the path is correct and try again.\r\n" \
                   "At line:1 char:1\r\n" \
                   "+ fake cmdlet\r\n" \
                   "+ ~~~~\r\n" \
                   "    + CategoryInfo          : ObjectNotFound: (fake:String) [], CommandNotFoundException\r\n" \
                   "    + FullyQualifiedErrorId : CommandNotFoundException\r\n" \
                   " \r\n"

        actual = Client.sanitise_clixml(clixml)
        assert actual == expected
Example #3
0
    def test_sanitise_clixml_not_clixml(self):
        clixml = "stderr line"
        expected = clixml

        actual = Client.sanitise_clixml(clixml)
        assert actual == expected
Example #4
0
import os
from pypsrp.client import Client

username = os.environ["ANSIBLE_WIN_USER"]
password = os.environ["ANSIBLE_WIN_PASSWORD"]
print(username)
print(password)

# this takes in the same kwargs as the WSMan object
client = Client("localhost", port=5985, ssl=False, cert_validation=False, username=username, password=password)
# execute a cmd command
stdout, stderr, rc = client.execute_cmd("dir")
print(stdout)
stdout, stderr, rc = client.execute_cmd("powershell.exe gci $pwd")
print(stderr)

exit()

sanitised_stderr = client.sanitise_clixml(stderr)
# execute a PowerShell script
output, streams, had_errors = client.execute_ps('''$path = "%s"
if (Test-Path -Path $path) {
    Remove-Item -Path $path -Force -Recurse
}
New-Item -Path $path -ItemType Directory''' % path)
output, streams, had_errors = client.execute_ps("New-Item -Path C:\\temp\\folder -ItemType Directory")
# copy a file from the local host to the remote host
client.copy("~/file.txt", "C:\\temp\\file.txt")
# fetch a file from the remote host to the local host
client.fetch("C:\\temp\\file.txt", "~/file.txt")