powershell returning 1 single element instead of array -
i have followed different posts on web fix issue code still returns single element insteaf of array. code below:
add-pssnapin -name veeampssnapin -warningaction silentlycontinue $sessionvmsummary = @() $bkjobs = get-vbrjob | foreach { $session = $_.findlastsession() if (($session -ne $null) -and ($_.isscheduleenabled -eq $true)) { # 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 make $sessionvmsummary return array whith 1 element? question 2: how can make code more efficient grammar point of view?
thanks
use comma operator wrap array in array e.g.:
return ,$sessionvmsummary
Comments
Post a Comment