VMware Cloud Community
cn41
Enthusiast
Enthusiast

CMDlets...scripts..

I have been trying for two days to just pipe out VM names, IPs and Mac addresses.  I just be able to just use this...

$report =@ ()

Get-VM | Get-View | %{$VMname = $_.Name

$_.guest.net | where {$_.MacAddress -eq "xx:xx:xx:xx:xx:" | ${

     $row = "" | Select VM, MAC

     $row.vm = $VMname

     $row.Mac = $_.MacAddress

     $report =+= $row

}

}

$report.

so, this isn't working,

I also can't get the samples scripts to run either.  The assisted script GetVMGuestNetworkInterface_windows....  would give me what I need...but where do you run this..from powerCli or powershell?  and how do you run it from powercli?  Never used the scripts before, I always just put together cmdlets...so this is a bit overwhelming..

Please help!!!:smileyconfused:

7 Replies
LucD
Leadership
Leadership

Try like this

$report =@()

Get-VM | Get-View | %{

    $VMname = $_.Name

    $_.guest.net | where {$_.MacAddress -eq "xx:xx:xx:xx:xx:" | %{

       $row = "" | Select VM, MAC

       $row.vm = $VMname

       $row.Mac = $_.MacAddress

       $report =+= $row

    }

}

$report


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

0 Kudos
cn41
Enthusiast
Enthusiast

thanks LucD, I typed it directly like listed.  This should take long on a vCenter with only 115 Vms right?

0 Kudos
cn41
Enthusiast
Enthusiast

because, i'm not feeling like i'm actually inputting this wrong..Its been a few months since I have used Power Cli..

$report =@()  *press enter?

Get-VM | Get-View | %{  *press enter?

*tab $VMname = $_.Name

should I be inputting it that way..as of right now, I have no results, which makes me think I didnt' input it correctly.

:smileyconfused::smileyconfused:

0 Kudos
LucD
Leadership
Leadership

I would suggest saving the code in a file with .ps1 extension.

Then from the PowerShell command prompt execute the .ps1 file.

Xtravirt did a good guide for beginners, see here


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

cn41
Enthusiast
Enthusiast

thanks, but it fails as a ps.1...I'll keep plucking away..

0 Kudos
Wh33ly
Hot Shot
Hot Shot

Just copy the code and paste in the powershell window, this will work.

Don't use enter between {  }  this will break it

0 Kudos
LucD
Leadership
Leadership

Can you attach the .ps1 as a file ?

I will have a look


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

0 Kudos