Reputation: 3067
I have followed different posts on the web to fix this issue but my code still returns a single element insteaf of array. My code below:
Add-PSSnapin -Name VeeamPSSnapIn -WarningAction SilentlyContinue
$sessionVMSummary = @()
$bkJobs = get-vbrjob | foreach {
$session = $_.findlastsession()
if (($session -ne $NULL) -and ($_.isScheduleEnabled -eq $TRUE)) {
# Get session details
$sessionDocument = New-Object PSObject -Property @{
"Name" = $session.JobName
"Result" = $session.Result.toString()
"ObjectStatus" = @()
}
[Veeam.Backup.Core.CBackupTaskSession]::GetByJobSession($session.id) | foreach {
$Info = New-Object PSObject -Property @{
"Start Time" = $_.Progress.StartTime
"End Time" = $_.Progress.StopTime
"Duration" = $_.Progress.Duration
}
$sessionDocument.ObjectStatus += $Info
}
$sessionVMSummary += $sessionDocument
}
}
return $sessionVMSummary
Question 1: How can I make $sessionVMSummary to return an array whith 1 element? Question 2: How can I make my code more efficient from the grammar point of view?
thanks
Upvotes: 2
Views: 938
Reputation: 201652
Use the comma operator to wrap your array in another array e.g.:
return ,$sessionVMSummary
Upvotes: 4