Recently I needed to create a connection to a Windows server and perform some operations on it. From there I wanted to run commands on the Windows server itself, and I didn’t want to have to worry about double hop WinRM issues from PowerShell. I wanted something flexible that I could use as a template moving forwards. After a fair bit of fiddling I finally got it to work and even better, I didn’t need vRO – it could all be completed from an extensibility action written in Python. Below is the code demonstrating the execution of a simple Windows command, ipconfig. If you were using this in production, you would obviously use Action Constants to keep the username, password and IP details secure, admitted here to make it easier for you to follow. In addition, you may want to look into using an SSH key and amending the set_missing_host_key_policy method.

def handler(context, inputs):
    import paramiko

    ssh = paramiko.SSHClient()

    # set variables
    target_server = ""
    Username = "administrator@automationpro.lan"
    Password = "T0pS3cre3tS@uce!!"
    # Command to run on the target
    exec_command = "ipconfig.exe /all"
    # Connect to target using username/password authentication.
    ssh.connect(hostname=target_server, username=Username, password=Password, look_for_keys=False)
    # Run command.
    (ssh_stdin, ssh_stdout, ssh_stderr) = ssh.exec_command(exec_command)
    output = ssh_stdout.readlines()
    # Close connection.
    outputs = {'output': output}
    return outputs


Note that the code has a dependency on a Python library, called paramiko. You will need to enter specify this dependency to obtain the library and have it injected into the ABX container at runtime.

And here is the output of the action in vRA.



CIO at Sonar, Automation Practice Lead at Xtravirt and guitarist in The Waders. Loves IT, automation, programming, music