0

sorry if the title is a bit confusing, honestly i did not know how to put it in plain words or what exactly to search for. I have an output from command line showing as per below.

Remote Copy System Information
Status: Started, Normal

Target Information

Name        ID Type Status Options Policy
3PARSYSTEM1  2 IP   ready  -       mirror_config

Link Information

Target      Node  Address      Status Options
3PARSYSTEM1 0:3:1 xxx.xxx.xxx.xxx Up     -
3PARSYSTEM1 1:3:1 xxx.xxx.xxx.xxx Up     -
receive     0:3:1 receive      Up     -
receive     1:3:1 receive      Up     -

Group Information

Name         Target      Status   Role       Mode     Options
GRP001Temp   3PARSYSTEM1 Started  Primary    Periodic Last-Sync 2018-11-04 00:08:09 MYT, Period 3h,over_per_alert
  LocalVV        ID   RemoteVV         ID   SyncStatus    LastSyncTime
  LUN001-Temp 13304 LUN001-TempDR 16914 Synced        2018-11-04 00:08:10 MYT

Name              Target      Status   Role       Mode     Options
GRP002-PHY01 3PARSYSTEM1 Started  Primary    Periodic Last-Sync 2018-11-04 01:17:54 MYT, Period 2h,auto_recover,over_per_alert
  LocalVV          ID   RemoteVV         ID   SyncStatus    LastSyncTime
  LUN001-VVT2.12  120 LUN001-VVT2.12  210 Syncing (33%) 2018-11-03 23:51:04 MYT

Name              Target      Status   Role       Mode     Options
GRP003-PHY02 3PARSYSTEM1 Started  Primary    Periodic Last-Sync 2018-11-04 01:27:12 MYT, Period 1h45m,auto_recover,over_per_alert
  LocalVV          ID   RemoteVV         ID   SyncStatus    LastSyncTime
  LUN002-VVT2.14  130 LUN002-VVT2.14  207 Syncing (49%) 2018-11-03 23:59:27 MYT

Name              Target      Status   Role       Mode     Options
GRP001-PRD-ORA 3PARSYSTEM1 Started  Primary    Periodic Last-Sync 2018-11-04 00:45:09 MYT, Period 2h,auto_recover,over_per_alert
  LocalVV                      ID   RemoteVV                     ID   SyncStatus    LastSyncTime
  ORA-PROD-VG01.35   97 ORA-PROD-VG01.35 2451 Synced        2018-11-04 00:45:54 MYT
  ORA-PROD-VG02.36   98 ORA-PROD-VG02.36 2452 Synced        2018-11-04 00:46:10 MYT
  ORA-PROD-VG03.37   99 ORA-PROD-VG03.37 2453 Synced        2018-11-04 00:45:48 MYT
  ORA-PROD-VG04.38  100 ORA-PROD-VG04.38 2454 Synced        2018-11-04 00:45:12 MYT
  ORA-PROD-VG05.39  101 ORA-PROD-VG05.39 2455 Synced        2018-11-04 00:45:12 MYT

Name              Target      Status   Role       Mode     Options
GRP001-PRD-SAP 3PARSYSTEM1 Started  Primary    Periodic Last-Sync 2018-11-04 01:24:25 MYT, Period 23m,auto_recover,over_per_alert
  LocalVV                 ID   RemoteVV                ID   SyncStatus    LastSyncTime
  SAP-PROD-APPS.4        80 SAP-PROD-APPS.4      1474 Synced        2018-11-04 01:24:28 MYT
  SAP-PROD-LOCK.19       95 SAP-PROD-LOCK.19     1490 Synced        2018-11-04 01:24:25 MYT
  SAP-PROD-SAPDT1.5      81 SAP-PROD-SAPDT1.5    1475 Synced        2018-11-04 01:25:16 MYT
  SAP-PROD-SAPDT2.6      82 SAP-PROD-SAPDT2.6    1476 Synced        2018-11-04 01:25:05 MYT
  SAP-PROD-SAPDT3.7      83 SAP-PROD-SAPDT3.7    1477 Synced        2018-11-04 01:25:07 MYT
  SAP-PROD-SAPDT4.8      84 SAP-PROD-SAPDT4.8    1478 Synced        2018-11-04 01:25:41 MYT
  SAP-PROD-SAPDT5.9      85 SAP-PROD-SAPDT5.9    1479 Synced        2018-11-04 01:25:35 MYT
  SAP-PROD-SAPDT6.10     86 SAP-PROD-SAPDT6.10   1480 Synced        2018-11-04 01:25:56 MYT

Name              Target      Status   Role       Mode     Options
GRP002-PRD-SAP 3PARSYSTEM1 Started  Primary    Periodic Last-Sync 2018-11-04 01:24:55 MYT, Period 23m,over_per_alert
  LocalVV          ID   RemoteVV          ID   SyncStatus    LastSyncTime
  SAP-PROD-VG01.10   15 SAP-PROD-VG01.10 29769 Synced        2018-11-04 01:28:44 MYT

and i want to use powershell to capture the group information and so that i can get the groupname and run another command to loop through the group name. example output is as per below.

GRP001Temp
GRP002-PHY01
GRP003-PHY02
GRP001-PRD-ORA
GRP001-PRD-SAP
GRP002-PRD-SAP

Hope you can help me with my problem. Thank You in advance.

3 Answers 3

1

if every group is in the Role "Primary" one easy way might be the following statement:

get-content Demo.txt | where { $_ -match "Primary" } | % { $_.Split(" ")[0] }  

It gets the lines which contain the word "Primary" and takes the first word (in your case the group name)

Sign up to request clarification or add additional context in comments.

Comments

0

You can split the output by the linebreak and loop over the result. If a line starts with Name, split the next line by a space and write the first element to the output.

Something like:

param($output)

$lines = $output -split [Environment]::NewLine
$name = $false
foreach($line in $lines) {
    if($name) {
        ($line -split ' ')[0] | Write-Output
        $name = $false
    }
    if($line.Startswith('Name')) {
        $name = $true
    }
}

1 Comment

thank you everyone for helping.. appreciate your kind contribution in providing the code to my problem. All code works as expected however this one is the best one to use in various situation.
0

Obviously you are after the first word following the Header

Name         Target      Status   Role       Mode     Options

Not including the false header

Name        ID Type Status Options Policy

the other answers aren't excluding.

So I'd split the file content with a RegEx by this Header into sections and skip the first one.
Then split each section into words separated with white space \s and get the first [0]

(Get-Content .\SO_53154266.txt -raw) -split "(?sm)^Name\s+Target.*?`r?`n" |
  Select-Object -skip 1|
    ForEach-Object { ($_ -split '\s')[0] }

Sample output:

GRP001Temp
GRP002-PHY01
GRP003-PHY02
GRP001-PRD-ORA
GRP001-PRD-SAP
GRP002-PRD-SAP

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.