vmware - Integrate powercli commands with Python scripts -


when run commands on power cli displays operations have performed.
example

start-vm –vm “vm1”   

simply starts vm in v center.

i want write such code in python can call these commands in code , store output , display user.
there way link our python code power cli commands or can can bind power cli code inside python?

you want 2 things: dot source script (which (as far know) similar python's import), , subprocess.call.

import subprocess subprocess.call(["c:\\windows\\system32\\windowspowershell\\v1.0\\powershell.exe", ". \"./samplepowershell\";", "&hello"]) 

so happens here start powershell, tell import script, , use semicolon end statement. can execute more commands, namely, hello.

you want add parameters functions, let's use 1 article above (modified slightly):

function addone($intin) { write-host ($intin + 1) } 

and call function whatever parameter want, long powershell can handle input. we'll modify above python to:

import subprocess subprocess.call(["c:\\windows\\system32\\windowspowershell\\v1.0\\powershell.exe", ". \"./samplepowershell\";", "&addone(10)"]) 

this gives me output:

powershell sample says hello. 11 

you'll need edit above include powercli library, should work.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -