Connection to all vCenters function

I've got following the following function which connects to a series of vCenters and generates a CSV file that contains the information of the virtual computer. The problem is that I have three vCenters, and the function runs but generates CSVs duplicate for each vCenter. The report contains details for each virtual computer in all three well vCenters even if only connected to one. Can we see what is happening here?

Function Get_VMs ($vcenter) {}

$MyCollection = @)

$AllVMs = get-View - ViewType VirtualMachine

$SortedVMs = $AllVMs | Select *, @{N = "NumDisks"; E={@($_. Guest.Disk.Length)}} | Sort-Object-down NumDisks

ForEach ($VM to $SortedVMs)

{

$template = get-model $VM.name - EA SilentlyContinue

$powerstate = get - vm $VM.name | Select PowerState - ExpandProperty PowerState | Out-string

$DiskNum = 0

If {($template)

$Cluster = get-Cluster - VMHost (Get-View-id $template. HostId). Name | Select the name of ExpandProperty-

$Details = new-object PSObject

$Details | Add-Member-vCenter name-value $vcenter - Membertype NoteProperty

$Details | Add-Member-Name name-value $VM.name - Membertype NoteProperty

$Details | Add-Member-name model, value 'TRUE' - Membertype NoteProperty

$Details | Add-Member-name PowerState-value ""-Membertype NoteProperty

$Details | Add-Member-name Cluster-value $Cluster - Membertype NoteProperty

$Details | Add-Member-name "Disk" - MemberType NoteProperty-value «»

$Details | Add-Member-name "DiskPath" - MemberType NoteProperty-value «»

$Details | Add-Member-name "DiskCapacity (GB)" - MemberType NoteProperty-value «»

$MyCollection += $Details

$template = $null

}

else {}

Foreach ($disk in $VM. Guest.Disk)

{

$Cluster get-Cluster - VM = $VM.name | Select the name of ExpandProperty-

$Details = new-object PSObject

$Details | Add-Member-vCenter name-value $vcenter - Membertype NoteProperty

$Details | Add-Member-Name name-value $VM.name - Membertype NoteProperty

$Details | Add-Member-name model-value 'FALSE' - Membertype NoteProperty

$Details | Add-Member-name PowerState-value $powerstate - Membertype NoteProperty

$Details | Add-Member-name Cluster-value $Cluster - Membertype NoteProperty

$Details | Add-Member-name "Disk" - MemberType NoteProperty-value $($DiskNum)

$Details | Add-Member-name "DiskPath" - MemberType NoteProperty-value $Disk.DiskPath

$Details | Add-Member-name "DiskCapacity (GB)" - MemberType NoteProperty-value ($disk. Capacity / 1 GB)

$DiskNum ++

$MyCollection += $Details

}

}

}

$csv = "$ScriptPath\vms\$ vcenter" + "_VMs.csv."

$MyCollection | Export-Csv - UseCulture - $csv NoTypeInformation

}

To sum up, the above function connects to a vCenter and collects information from the VM for three vCenters including the two, that it is not connected. Then did the same for the next two (as noted below in a loop that executes the function). The loop is tried and tested and just copied from several of my existing scripts.

Thanks in advance
Adam

Is there a difference when you use the Server parameter on all PowerCLI cmdlets?

Function Get_VMs ($vcenter) {}

$MyCollection = @)

$AllVMs = get-View - ViewType VirtualMachine-Server $vcenter

$SortedVMs = $AllVMs | Select *, @{N = "NumDisks"; E={@($_. Guest.Disk.Length)}} | Sort-Object-down NumDisks

ForEach ($VM to $SortedVMs)

{

$template = get-model $VM.name - server $vcenter - EA SilentlyContinue

$powerstate = $VM | Select PowerState - ExpandProperty PowerState | Out-string

$DiskNum = 0

If {($template)

$Cluster = get-Cluster - VMHost (Get-View-id $template. HostId). Name - Server $vcenter | Select the name of ExpandProperty-

$Details = new-object PSObject

$Details | Add-Member-vCenter name-value $vcenter - Membertype NoteProperty

$Details | Add-Member-Name name-value $VM.name - Membertype NoteProperty

$Details | Add-Member-name model, value 'TRUE' - Membertype NoteProperty

$Details | Add-Member-name PowerState-value ""-Membertype NoteProperty

$Details | Add-Member-name Cluster-value $Cluster - Membertype NoteProperty

$Details | Add-Member-name "Disk" - MemberType NoteProperty-value «»

$Details | Add-Member-name "DiskPath" - MemberType NoteProperty-value «»

$Details | Add-Member-name "DiskCapacity (GB)" - MemberType NoteProperty-value «»

$MyCollection += $Details

$template = $null

}

else {}

Foreach ($disk in $VM. Guest.Disk)

{

$Cluster = get-Cluster - VM $VM.name - Server $vcenter | Select the name of ExpandProperty-

$Details = new-object PSObject

$Details | Add-Member-vCenter name-value $vcenter - Membertype NoteProperty

$Details | Add-Member-Name name-value $VM.name - Membertype NoteProperty

$Details | Add-Member-name model-value 'FALSE' - Membertype NoteProperty

$Details | Add-Member-name PowerState-value $powerstate - Membertype NoteProperty

$Details | Add-Member-name Cluster-value $Cluster - Membertype NoteProperty

$Details | Add-Member-name "Disk" - MemberType NoteProperty-value $($DiskNum)

$Details | Add-Member-name "DiskPath" - MemberType NoteProperty-value $Disk.DiskPath

$Details | Add-Member-name "DiskCapacity (GB)" - MemberType NoteProperty-value ($disk. Capacity / 1 GB)

$DiskNum ++

$MyCollection += $Details

}

}

}

$csv = "$ScriptPath\vms\$ vcenter" + "_VMs.csv."

$MyCollection | Export-Csv - UseCulture - $csv NoTypeInformation

}

Tags: VMware

Similar Questions

  • ePrint not connected but all other functions work

    I've just implemented the of HP216B all-in-One printer. All wireless connections are perfect and I can print from multiple connected wireless laptops and a desktop connected via ethernet to the router. All the basic functions of printing, sca, working copy. I followed all of the Web Services and that seemed to work. Wireless test shgows all to be in perfect condition. I have an IP address, etc.. However, when I'm in the ePrintCentre shows printer not connected and when I try to send an email to the printer it appears as pending in print jobs. Clearly, the printer is not connected to the internet and which is also verified by the fact that the PrintApps can not download print from the web site of hpcentre.

    I turned the printer off and on again. I deleted the printer and added it again - everything to nothing will do. I looked through the forums and still have no success.

    Anyone any ideas?

    OK, it's working now. Don't know why or how but several attempts to turn on the printer and to the wide coupled with e-mail delivery address worked. I also changed from specifying eligible email addresses that all and today my impressions arrived. Oddly enough, I also have to turn off the printer on ana to reactivate the connection to my office and computers scan all laptops connected via the router.

    I am happy that it is not a plug-and-play or a transparent solution that is described on the semi box

  • My thunderbird (windows 8) essentially has stopped working. More than one minute to open an email - all other functions have similar delays. What should I do?

    For some reason, thunderbird (windows 8) essentially has stopped working. More than one minute to open an email - all other functions have similar delays. I tried to archive, but I get a message that says that a script has stopped working. He does the same in thunderbird safe mode. My old computer (XP) works very well. I can't find my profiles on windows 8 to rebuild the database world.

    Follow-up: McAfee was the problem. I contacted them via chat. Remotely, they took control of my computer and changed the settings. TBird works fine now.

    Thank you for all your help.

  • I have five Airport extreme with their network of people names different location home.  I have a brighthouse router that I use to connect to all the extremes of the airport.  I experienced the problem of connection to the internet.

    I have five airport extreme, with their network of people of names in a different location in the House.  I have a brighthouse router that I use to connect to all the extremes of the airport.  I experienced the problem of connection to the internet.

    Are all connected to the Brighthouse router by Ethernet extremes? Are all of the extremes configured as bridges?

  • Re: Satellite Pro A300-1EA - wireless connection, drop all the time

    Hi, I have a problem with my wireless connection fall all the time on my Satellite Pro A300 1EA.

    It happened earlier, but I've fiddled about a little with change of drivers and the removal of the connection settings for the registry and it then worked fine for months, until yesterday.

    There were several updates for Windows installed yesterday, but none of them have been updated driver for the wireless card, and they don't look like they should cause problems. The fact that the problem happened before makes me think that the updates can be anything to do with it.

    I use the * Intel PRO/Wireless 3945/4965/5100/5300 * for Vista 32 - bit version 12.2.0.11.3 drivers from the Toshiba download page.

    Other computers on the same access point have no problem, so I think it is specific to this laptop. The connection speed is normally 6 Mbps, but I cannot even check e-mail now without the abandonment of the connection.

    Laptop will be thrown against a wall soon if no one can help you.

    Thanks in advance.

    Edit: I've already made sure power settings are at maximum to the WLAN card, even if on battery, or what power management.

    Post edited by: mjbcrawf

    Hello

    Have you tried to use the Windows System Restore feature? After that your WLAN should work fine again.

    In addition, I can recommend the latest WLAN driver in the Intel page, it s version 12.4.xxxx. I installed the driver on my Qosmio laptop and don t have any problems with it: [www.intel.com].

    If you have any other questions, please let us know!

  • My BT Broadband connects to all other devices except my MacBook Pro, help?

    My BT Broadband connects to all other devices except my MacBook Pro, help?

    You use a wired connection to the router or WIFI?

    If the latter can you see other networks on your computer, and you can see your own network?

  • my Macbook just stop to connect to one of my yahoo email (failed connection) accounts can I connect on all my other devices

    my Macbook just stop to connect to one of my yahoo email (failed connection) accounts can I connect on all my other devices

    Delete and re add the password for that account or delete and re add this email account.

  • How can I fix a black and white screen on the air from my iPad? I rebooted it and ran the last updated IOS 9.2 on it. It is stuck and won't return to the color. All other functions work except this.

    How can I fix a black and white screen on the air from my iPad? I rebooted it and ran the last updated IOS 9.2 on it. It is stuck and won't return to the color. All other functions work except this.

    Have you checked the settings > General > accessibility > greyscale > power off.

    If this does not work ty settings > General > accessibility > zoom > on. Triple, tap the screen with three fingers. Tap choose filter. Click None. Triple, tap the screen to get rid of the menu zoom. If you have enabled greyscale in zoom you can disable it in zoom.

  • My wifi will display all the available connections, but all of a sudden that stopped

    Former title: Wifi

    My wifi to view all the available connections, but all of a sudden that stopped. Wifi is turned on and there is here the wifi connections I used but now how do they return?

    Hello

    I suggest you try to update the latest drivers for the network adapter and check if it helps:

    http://Windows.Microsoft.com/en-us/Windows7/update-a-driver-for-hardware-that-isn ' t-work correctly

    For more information, see these links:

    http://Windows.Microsoft.com/en-us/Windows7/view-and-connect-to-available-wireless-networks

    http://Windows.Microsoft.com/en-us/Windows7/wireless-networking-frequently-asked-questions

    It will be useful.

  • I can't get on my hotmail account - internet connects to all other Web sites, but not Hotmail. Any ideas?

    I got in trouble for the week when you log in to my hotmail account. Internet connects to all other sites Web but Hotmail. You have any suggestions to solve this problem. It's really annoying. Thanks adrienne

    After all the Hotmail issues in the appropriate forum found here:
    http://windowslivehelp.com/

  • How to replace a bad IDE disk with a USB Flash drive system - and have all the functionality of XP Pro SP3

    How to replace a bad IDE disk with a USB Flash drive system - and have all the functionality of XP Pro SP3
    Given a PC without hard disk...
    How can you use a flash drive instead?
    So, indeed, the USB key works as an SSD...
    I saw online options that gives partial functionality of the system... and an option that is more than $100 (more than the system's worth)...
    None of these options are acceptable in the circumstances.
    It is an effort to create a machine for a particular use, built from a recycled pc for which hard drive was removed and destroyed by the original owner...
    The criterion is that it must work just like it was a mechanical drive running xp pro sp3 with all updates, etc...
    Thanks for any help.

    You can not install XP on a Flash as his unsupported drive. Your only two options are a traditional hard drive or Solid State Drive (SSD).

    J W Stuart: http://www.pagestart.com

  • Have had a reliable networking until recently. Today, I can not connect at all. LAN is not seen at all.

    original title: network connectivity

    Have had a reliable networking until recently.  Today, I can not connect at all.

    Wired and wireless connections are not available. This position is limited to wired connectivity.

    1. network and sharing shows disabled wireless network and a public network, unidentified.  LAN is not seen.

    2 Troubleshooting could identify the problem

    3. have you seen respectable network adapters and sharing that I do not beleve are correct.

    4. the LAN adapter works in Device Manager

    5 IP config says media disconnected

    Advice requested

    Hello

    Have you made changes on the computer before this problem?

    The following articles may be useful:

    How to troubleshoot possible causes of Internet connection problems in Windows XP
    http://support.Microsoft.com/kb/314095
    Windows wireless and wired network connection problems
    http://Windows.Microsoft.com/en-us/Windows/help/wired-and-wireless-network-connection-problems-in-Windows

  • When asked "do you want to enable Network Service list? I continue to by clicking on the button "Activate this", and yet I am not able to see the activities or connections to all networks.

    When asked "do you want to enable Network Service list? I continue to by clicking on the button "Activate this", and yet I am not able to see the activities or connections to all networks. My internet works fine, I just can't see if I am connected or not. Help?

    original title: list of Network Service does not illuminate

    Hi SikDude,

    Please use the Forum of the community for Vista.

    Opening of services by typing services.msc in the search bar and find the list of Network Service. Under properties, set it to automatic.

    Please let us know if we can do something else.

    Matt
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • RE1000 abandon the connection of all devices

    I recently bought a RE1000. It worked very well for the first two days. Then, he started to drop connections on all devices on both the main router, a Linksys E2000 and the Extender. I have reset several times and just did one today. Can anyone tell me the reason why it continues to be now?

    -ADM network

    So far so good!

  • laptop won't connect at all!

    Hello
    My laptop connects is no longer to form any internet connection. I tried the WiFi connection of my laptop directly to the box, hotspot, mobile, and taking my computer to different places with wireless (panera, mcdonnalds etc.), nothing works. I ran about 3 different scans on my computer, including a start-up deep scan and it still does not work... Can someone tell me what is the problem? It all started when we received a new box of our supplier (windstream) wireless... IM the only one who can't get things to connect. All will connect but my laptop and Nintendo Wii
    Any advise?

    Hi @xxfireflies27,

    Thank you for the information. I suggest some use Microsoft System Restore (Windows 7) to restore your laptop to a date where he worked.

    If this does not resolve the problem, then you are looking to recover Windows 7 operating system using Microsoft Windows Backup and Restore.

    I hope this helps, keep me posted on how it goes.

    Good luck and have a great day!

Maybe you are looking for