First , use of VS2010 to build a project, reference System.Management.Automation.dll,
and then call the Veeam cmdlet:"Get-VBRBackup" and "Get-VBRServer" returned values are correct,
but the implementation of "Find-VBRResourcePool" access resource pool, value iempty
Code: Select all
using (Runspace runspace = RunspaceFactory.CreateRunspace())
{
runspace.Open();
//Create Pipeline
using (Pipeline pipeline = runspace.CreatePipeline())
{
pipeline.Commands.AddScript("Add-PSSnapin VeeamPSSnapIn");
pipeline.Commands.AddScript("$rp = Get-VBRBackup | where {$_.JobName -eq 'BackupJob1'} | Get-VBRRestorePoint|where {$_.VMName -eq 'vm--test-Win2K3R2wSP2'}");
pipeline.Commands.AddScript("$server = Get-VBRServer | where {$_.Name -eq 'hke-ssvr1.dyxnet.com'} ");
pipeline.Commands.AddScript("$server ");//can get data
pipeline.Commands.AddScript("$res = Find-VBRResourcePool -Server ($server) | where {$_.Name -eq 'vctest2'} ");
pipeline.Commands.AddScript("$res");//empty
pipeline.Commands.AddScript("$datast = Find-VBRDatastore -Server ($server) | where {$_.Name -eq 'stogp1_m800tnas1'}");
pipeline.Commands.AddScript("Start-VBRRestoreVM -ResotePoint $rp -Server ($server) -ResourcePool ($res) -Datastore ($datast) -VMName 'vm--test-Win2K3R2wSP2' -DiskType 'thin' -PowerUp $TRUE");
//out-string
pipeline.Commands.Add("Out-String");
//get return string
Collection<PSObject> results = pipeline.Invoke();
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
{
stringBuilder.AppendLine(obj.ToString());
}
runspace.Close();
return stringBuilder.ToString();//return
}
}
Only when the call with System.Management.Automation.dll to call "Find-VBRResourcePool" or " Find-VBRDatastore", the value is null