How to get the Powershell environment variables value into C++ program

  • Thread starter Thread starter ananda vardhana
  • Start date Start date
A

ananda vardhana

Guest
wstring getVM = L"powershell -Command \"& {$TotalVM = Get-VM; $TotalVMCount = $TotalVM.count; echo $TotalVMsCount > VmCount.txt}\" ";
_wsystem(getVM.c_str());

The above 2 lines will work in a C++ code and the contents of VmCount.txt will have the VmCount. Now to get the VmCount into my C++ program I have to open the file do a getline() and then convert the string to int. Can I somehow get the value TotalVM.count straigt into my C++ without having to write to a file, open it, read it etc...

Something like int VmCount = $TotalVM.count???

thanks

ananda

Continue reading...
 
Back
Top