VMware Cloud Community
RWurgley
Contributor
Contributor
Jump to solution

problem displaying results with a duplicate mac script

I'm still fairly new to powershell scripting, and have learned quite a bit from reading the code others have put together here on the forum and other blogs. Given that, i still have a lot to learn and i'm having a really frustrating issue with a small script i was asked to put together.

The purpose of the script is to try to locate duplicate MAC addresses seperately for VM's, Host physical Nics, and VMKernal interfaces. So it first gathers all of the MAC addresses for each and stores them individually. It also combines each of them into an array, so that this way it can list duplicates they each have individually, as well as duplicates between them as well. When i run the ps1 file in powercli, i get partial results. The VMKernel area lists the mac address, but not the related host or portgroup name. The combined results end up completely empty. If i paste the exact contents of the ps1 file into powercli directly, it runs through correctly and displays all required information that is not there when i run the script file, except for the vmkernal host and portgroup name again. For some reason that one won't display all the information at all. I noticed that the amount of extra blank lines being displayed in the combined area are the same amount of lines of the results that come through when i just paste the script in. So its like it knows there is data, but just can't visually display it for some reason and i honestly don't know enough to figure out why. I assume its some kind of formatting issue, and i'm hoping someone can tell me what i'm doing wrong.

Attached is a copy of the script, as well as copy/paste's of the powercli window from running the script, and also just pasting the script into the window. Obviously though, my poor coding style makes it semi difficult to read where i just pasted the script contents into powercli.

Note: As per the vmworld session i attended with LucD as one of the hosts, i apoligize for killing puppies with my continuous use of write-host :smileyblush:  I haven't had time to look into the alternatives, and get myself used them as much yet.

I really appreciate any help that anyone can provide me


0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Great idea for a script.

I suspect your problem comes from this line

$combineddup = $combinedreport|Group-Object Mac |where {$_.Group -gt 1}

which should according to me be

$combineddup = $combinedreport|Group-Object Mac |where {$_.Group.Count -gt 1}

I attached a reviewed version of the script with a couple of other changes I would like to suggest. Have a look.

Feel free to ask if some of my proposed changes are not clear.

On the puppies, you're excused for the first 10 scripts you post in this community :smileygrin:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

Great idea for a script.

I suspect your problem comes from this line

$combineddup = $combinedreport|Group-Object Mac |where {$_.Group -gt 1}

which should according to me be

$combineddup = $combinedreport|Group-Object Mac |where {$_.Group.Count -gt 1}

I attached a reviewed version of the script with a couple of other changes I would like to suggest. Have a look.

Feel free to ask if some of my proposed changes are not clear.

On the puppies, you're excused for the first 10 scripts you post in this community :smileygrin:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos