I have created a custom object with 3 properties. The data in the properties is pulled from Backup Exec job log files.
$BackupServer = Get-Content C:\ITO\RB\ERRORS\STARTEND.TXT | Select-String -SimpleMatch 'Backup of "'
$BackupStartTime = Get-Content C:\ITO\RB\ERRORS\STARTEND.TXT | Select-String -SimpleMatch 'Backup started on'
$BackupEndTime = Get-Content C:\ITO\RB\ERRORS\STARTEND.TXT | Select-String -SimpleMatch 'Backup completed on'
I then created a customer object with custom properties
$props= [ordered]@{ ServerName = $backupserver
StartTime = $backupstarttime
EndTime = $BackupEndTime
Success = 'Did Backup Complete'
}
$obj = New-Object -TypeName psobject -Property $props
$objectoutput = $obj | Select @{n='Server Name';e={$_.ServerName -split ','+"`n"}}, @{n='Start Time';e={$_.StartTime -split '.'+"`n"}}, @{n='End Time';e={$_.EndTime -split '.'+"`n"}}
$objectoutput
The data in the array is what i want so I am happy so far.
Custom Object :
$objectoutput | Get-Member
TypeName: Selected.System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
End Time NoteProperty System.Object[] End Time=16/10/2017 at 06:04:38. 16/10/2017 at 06:04:57. 16/10/2017 at 06:05:11. 16/10/2017 at 06:05:42. 16/10/2017 at 06:08:31. 16/10/2017 at 06:09:03. 15/10/2017 at 20:07:30. 15/10/2017 at 20:09:49. ...
Server Name NoteProperty System.Object[] Server Name=server1.
SERVERVMWSUS SERVEROP5P01 SERVERLUDIP01 SERVERNEWMPLP04 SERVERURV2...
**Start Time** NoteProperty System.Object[] Start Time=16/10/2017 at 06:03:08. 16/10/2017 at 06:04:55. 16/10/2017 at 06:05:07. 16/10/2017 at 06:05:36. 16/10/2017 at 06:06:19. 16/10/2017 at 06:09:00. 15/10/2017 at 20:02:36. 15/10/2017 at 20:08:23...
When I call the array I get this. The data elements is in there. However it appears to be one long string of text.
$objectoutput
Server Name Start Time End Time
{ITOTFXSBK01.C, ITOTFXSBK01.EFISystemPartition, ITOTFXSBK01.BKUPEXEC, ITOTFXSB...
{16/10/2017 at 06:03:08., 16/10/2017 at 06:04:55., 16/10/2017 at 06:05:07., 16...
{16/10/2017 at 06:04:38., 16/10/2017 at 06:04:57., 16/10/2017 at 06:05:11., 16...
What i want is to have each server on a new line, there is a "space" that can be used to split the ServerName note property, for the StartTime and EndTime there is a "." that can be used to split.
In my final report I use this command to attempt to output how i want but its no good, ive tried lots of different combinations 'r 'n and -split and -join etc.
$rpt4+= Get-HtmlContentTable ($objectoutput | Select @{n='Server Name';e={$_.ServerName -split '\s+'}})
I am really struggling to work it out. The best i can do can be seen below: PICTUREHERE
Sample Data
$backupserver =
TELB2BDB01
TELCLUS01
TELADVDB01
TELSPDB01
TELSQL04
$BackupStarttime =
16/10/2017 at 04:10:43.
16/10/2017 at 04:12:07.
16/10/2017 at 02:02:38.
16/10/2017 at 02:01:02.
16/10/2017 at 02:01:32.
$BackupEndTime =
16/10/2017 at 04:11:51.
16/10/2017 at 04:13:14.
16/10/2017 at 02:06:17.
16/10/2017 at 02:02:10.
16/10/2017 at 02:02:52.