-1

Here is what I am trying to achieve...

I have to view the ADAM db in VMWARE to see the replication times. My question is how would I compare more than two strings using the compare-object command. I cannot find any articles on more than two values.

This is what I started writing. I am trying to make this as dynamic as possible...

#PORT FOR LDAP
$ldap = 389;

#PATH
$path = 'DC=vdi,DC=vmware,DC=int';

#SERVERS
$vm = @("fqdn" , "fqdn" , "fqdn");

#ARRAY FOR LOOP
$comp = @();

#LOOP FOR ARRAY COMPARE
for($i = 1; $i -le $vm.count; $i++)
{
    $comp += repadmin.exe /showrepl $svr":"$ldap $path | Select-String "Last attempt";
}

#CREATE DYNAMIC VARIABLES
for($i = 0; $i -le ($comp.count - 1); $i++)
{
    New-Variable -name repl$i -Value $comp[$i];
}

Thank you in advanced!!!

1 Answers1

0

As I mentioned in my comment, your question is too vague for us to provide a good answer for your situation, so I'll focus on "compare more than two strings". To do this, I wuold recommend Group-Object. Ex.

$data = @"
==== INBOUND NEIGHBORS ======================================

CN=Configuration,CN={B59C1E29-972F-455A-BDD5-1FA7C1B7D60D}
    ....
        Last attempt @ 2010-05-28 07:29:34 was successful.

CN=Schema,CN=Configuration,CN={B59C1E29-972F-455A-BDD5-1FA7C1B7D60D}
    ....
        Last attempt @ 2010-05-28 07:29:34 was successful.

OU=WSFG,DC=COM
    ....
        Last attempt @ 2010-05-28 07:29:35 failed, result -2146893008
(0x8009033
0):
"@ -split [environment]::NewLine

$comp = $data | Select-String "Last attempt"

$comp | Group-Object

Count Name                                                                  Group                
----- ----                                                                  -----                
    2         Last attempt @ 2010-05-28 07:29:34 was successful.            {        Last atte...
    1         Last attempt @ 2010-05-28 07:29:35 failed, result -2146893008 {        Last atte...

Group-Object and PowerShell is very flexible, so you could customize this to ex. display the servernames and status for the servers that wasn't equal to the rest (ex. count = 1 or not in any of the biggest groups) etc., but I won't spend more time going into details because I have no idea of what you are trying to achieve, so I'll probably just waste both of ours time.

Summary: What I can tell you is the I would proabably (99% sure) use Group-Object to "compare more than two strings".

Frode F.
  • 52,376
  • 9
  • 98
  • 114
  • That worked like a champ. Sorry, I seem to have misunderstood you when you said, "group object." I just ran it against 10 different servers and was able to get the results I was looking for. Again, Thank you! –  Sep 24 '14 at 20:01
  • 1
    Thank you Frode, I was writing something similar myself. I would just like to point out to the OP that the actual *functional* portion of the code there is one line. In fact, it's the one line that I suggested in my comment half an hour ago that you said makes the script really long. – TheMadTechnician Sep 24 '14 at 20:01
  • @Spontaneous1980 Glad I could help, but I hope you learned something today. :) Questions on SO should include all information necessary for others to reproduce and solve your problem. You need a clear description, a "working codesample"(yours didn't compare anything), input data to test with and wanted output. Instead of saying that you won't teach us AD, you could easily have provided sampledata like the one I used in my answer. A more detailed question would have given you a proper answer in 5 min. – Frode F. Sep 24 '14 at 20:08
  • @TheMadTechnician I know. I realized that our comments wheren't going through, so I finally decided to submit it as an answer. The question is too vague and I was very close to vote for close to be honest. – Frode F. Sep 24 '14 at 20:09