Text File to Formatted Table

I have the output below from navisecli command. I find it hard to convert the output to table into “MirrorView Name”, “Synchronizing Progress”
MirrorView Name: DUB-C2_SRMTEST01_L251
Synchronizing Progress(%): 100
MirrorView Name: DUB-C2_SYS02_L1
Synchronizing Progress(%): 0
MirrorView Name: DUB-C2_FC_LRP_SYS09_WK10
Synchronizing Progress(%): 100
MirrorView Name: DUB-C2_FC_LRP_SYS11_WK10
Synchronizing Progress(%): 100
MirrorView Name: DUB-C2_FC_LRP_SYS10_WK10
Synchronizing Progress(%): 100
MirrorView Name: DUB-C2_SYS03_L2
Synchronizing Progress(%): 100
MirrorView Name: DUB-C2_FC_LRP_SYS12_IDL
Synchronizing Progress(%): 100
MirrorView Name: ABU-C2_SYS03_L102
Synchronizing Progress(%): 67
MirrorView Name: DUB-C2_SYS01_L0
Synchronizing Progress(%): 100
MirrorView Name: DUB-C2_FC_LRP_SYS08_WK10
Synchronizing Progress(%): 100
MirrorView Name: DUB-C2_SYS06_L5
Synchronizing Progress(%): 100
MirrorView Name: ABU-C2_SYS02_L101
Synchronizing Progress(%): 34
MirrorView Name: ABU-C2_SYS06_L105
Synchronizing Progress(%): 12
MirrorView Name: ABU-C2_SYS05_L104
Synchronizing Progress(%): 100
MirrorView Name: DUB-C2_SYS07_L10
Synchronizing Progress(%): 0

You have to ask a question, please.

How can i format the output file into table, the Header would be “MirrorView Name” and “Synchronizing Progress”

:wink: :smiley: … you’re a funny guy, aren’t you? :wink:

I meant you should ask a question about the code you already wrote and you have problems with. It would be helpful when you show your code as well.

EDIT: OK … it’s Friday, I’m in a good mood and it’s almost closing time at work … lucky you. :wink:

$Content = Get-Content -Path 'C:\sample\output below from navisecli command.txt ’
$object = for ($i = 0; $i -lt $Content.Count; $i = $i + 2) {
[PSCustomObject]@{
MirrorViewName = ($Content[$i] -split ‘:’)[1].Trim()
SynchronizingProgress = [INT]($Content[$i + 1] -split ‘:’)[1].Trim()
}
}
$object

hahaha. Sorry for that. Here’s the code i have :

$File = C:\Temp\Test.txt
naviseccli -User ***** -Password ***** -Scope 0 -h SABUPVNX01 mirror -async -list -timestamp -all > $File
$object = Get-Content $shawn | Select-String -pattern “MirrorView Name:”, “Synchronizing Progress(%):”,“Previous update ended:”

The problem i have is to manipulate the output into table, since this is not a PSObject.

 

Hi Many Thanks. The Code is working fine on the above file.

But i have added another line in the output; how can i add another another header on that “(Previous update ended:”) . Below is the text file.

MirrorView Name: DUB-C2_SRMTEST01_L251
Synchronizing Progress(%): 100
Previous update ended: 5/3/2019 14:30:15
MirrorView Name: DUB-C2_SYS02_L1
Synchronizing Progress(%): 100
Previous update ended: 5/3/2019 14:40:45
MirrorView Name: DUB-C2_FC_LRP_SYS09_WK10
Synchronizing Progress(%): 100
Previous update ended: Not Available
MirrorView Name: DUB-C2_FC_LRP_SYS11_WK10
Synchronizing Progress(%): 100
Previous update ended: Not Available
MirrorView Name: DUB-C2_FC_LRP_SYS10_WK10
Synchronizing Progress(%): 100
Previous update ended: Not Available
MirrorView Name: DUB-C2_SYS03_L2
Synchronizing Progress(%): 100
Previous update ended: 5/3/2019 14:36:42
MirrorView Name: DUB-C2_FC_LRP_SYS12_IDL
Synchronizing Progress(%): 100
Previous update ended: Not Available
MirrorView Name: ABU-C2_SYS03_L102
Synchronizing Progress(%): 100
Previous update ended: 5/3/2019 14:36:45
MirrorView Name: DUB-C2_SYS01_L0
Synchronizing Progress(%): 0
Previous update ended: 5/3/2019 14:26:23
MirrorView Name: DUB-C2_FC_LRP_SYS08_WK10
Synchronizing Progress(%): 100
Previous update ended: Not Available
MirrorView Name: DUB-C2_SYS06_L5
Synchronizing Progress(%): 100
Previous update ended: 5/3/2019 14:34:29
MirrorView Name: ABU-C2_SYS02_L101
Synchronizing Progress(%): 44
Previous update ended: 5/3/2019 14:31:56
MirrorView Name: ABU-C2_SYS06_L105
Synchronizing Progress(%): 100
Previous update ended: 5/3/2019 14:40:48
MirrorView Name: ABU-C2_SYS05_L104
Synchronizing Progress(%): 0
Previous update ended: 5/3/2019 14:38:21
MirrorView Name: DUB-C2_SYS07_L10
Synchronizing Progress(%): 0
Previous update ended: 5/2/2019 19:27:35

It’s actually very easy. I’m pretty sure you can handle that by yourself. You just have to analyze my code example and extend it to your requirements. And you should read the help for the used cmdlets or functions or statements like about_for or about_split. You should always read the complete help including the examples to understand how to use it.

And please - when you post code or example data format this as code using the code tag button (pre) on the icon bar of the post editor (second to last icon). :wink:

Im just a beginner when it comes to powershell, and somehow understand your script above. I have added 1 line to your script to add another header. But i’m having error "Cannot convert value “5/7/2019 5:43:03” to type “System.Int32”. Error: “Input string was not in a correct format.”

$object = for ($i = 0; $i -lt $Content.Count; $i = $i + 2) {
    [PSCustomObject]@{
        "MirrorView Name" = ($Content[$i] -split ':')[1].Trim()
        "Synchronizing Progress" = [INT]($Content[$i + 1] -split ':')[1].Trim()
	"Previous Update Ended" = [INT]($Content[$i + 2] -split ':',2)[1].Trim()
    }
}
$object

OK. Instead of 2 lines you need to take 3 lines now. Therefor you have to change the repeat placeholder of your for loop from 2 to 3. For your new line the -split method will not work well because you have more than one split pattern in your search text … we can do this with a simple regex … like this:

$object = for ($i = 0; $i -lt $Content.Count; $i = $i + 3) {
($Content[$i + 2] -match ‘:\s+(\d+/\d+/\d+\s+\d+:\d+:\d+)’ | Out-Null )
[PSCustomObject]@{
MirrorViewName = ($Content[$i] -split ‘:’)[1].Trim()
SynchronizingProgress = [INT]($Content[$i + 1] -split ‘:’)[1].Trim()
PreviousUpdateEnded = Get-Date $Matches[1]
}
}
$object

Many Thanks. It works . Thanks for the help :slight_smile: