I m试图利用C++管理功能的PowerShell级履行WMI职能。
但是,我可以就如何在从PowerShell返回的PSObject名单中标出的物体上打上一种方法。 Invoke()方法。
(关于指挥线,我只做(gwmi ......)。 RequestStateChange(2)——但我可以看看如何使用PowerShell阶级的几种方法添加()。
System::Management::Automation::PowerShell ^ ps = System::Management::Automation::PowerShell::Create();
ps->AddCommand("Get-WMIObject");
ps->AddParameter("namespace", "root/virtualization");
p->AddParameter("class", "Msvm_ComputerSystem");
// we could add a filter to only return the VM in question but
// I had problems with quoting so choose the
// simplier route.
System::Collections::ObjectModel::Collection<System::Management::Automation::PSObject^>^ result = ps->Invoke();
System::String ^s = gcnew System::String( id.c_str() );
for (int i = 0; i < result->Count; i++ ) {
if ( System::String::Compare( dynamic_cast<System::String ^>(result[i]->Members["Name"]->Value), s) == 0 ) {
// Now what ? I want to call the RequestStateChange method on this VM
return;
}
}