Code: Select all
$obj = Get-VBRBackup -Name server.name.com
$storages = $obj.GetStorages()
$storages.Info
$storages.Stats
The corresponding C# code is:
Code: Select all
Pipeline getVbrBackup = PowerShellHost.createPipeLine();
Command GetVbrBackup = new Command("Get-VBRBackup");
GetVbrBackup.Parameters.Add("Name", Name);
getVbrBackup.Commands.Add(GetVbrBackup);
Collection<PSObject> backups = PowerShellHost.invoke(getVbrBackup);
if (backups.Count == 0)
{
return null;
}
Pipeline getStorages = PowerShellHost.createPipeLine();
getStorages.Commands.AddScript("$backup = Get-VBRBackup -Name '" + Name + "'");
getStorages.Commands.AddScript("$storages = (Get-VBRBackup -Name $backup.Name).GetStorages()");
getStorages.Commands.AddScript("$storages");
Collection<PSObject> storages = PowerShellHost.invoke(getStorages);
Pipeline getInfo = PowerShellHost.createPipeLine();
getInfo.Commands.AddScript("$backup = Get-VBRBackup -Name '" + Name + "'");
getInfo.Commands.AddScript("$info = (Get-VBRBackup -Name $backup.Name).GetStorages() | % { $_.Info }");
getInfo.Commands.AddScript("$info");
Collection<PSObject> infos = PowerShellHost.invoke(getInfo);
Pipeline getStats = PowerShellHost.createPipeLine();
getStats.Commands.AddScript("$backup = Get-VBRBackup -Name '" + Name + "'");
getStats.Commands.AddScript("$stats = (Get-VBRBackup -Name $backup.Name).GetStorages() | % { $_.Stats }");
getStats.Commands.AddScript("$stats");
Collection<PSObject> stats = PowerShellHost.invoke(getStats);
return VBRBackup.fill(backups[0], storages, infos, stats);
Can anyone tell me if I've missed something obvious, or if a better approach exists to retrieve all the information in a VBRBackup using C#?