Script to list all the warehouses of data in a cluster, the virtual machines on the data store and the host of the virtual machine is on

We have warehouses of data which are seen by more than one cluster. I need a script that will display:

all stores of data seen by a cluster

the virtual machines on the data store

the host of the virtual machine is on

the cluster the host is in

The output I want is

name of the store of data, the VM name, host name, the name of the Cluster

any help would be appreciated

Pretty sure this will do what you need:

$report = @()
Foreach($cluster in Get-Cluster){
    $datastores = $cluster | Get-VMHost | Get-Datastore
    foreach($datastore in $datastores){
    $vms = $datastore | Get-VM
    If ($vms.count -ge 1){
        foreach($VM in $vms){
        $object = New-Object -TypeName PSObject -Property @{
              Datastore = $datastore.Name
              VM = $VM.Name
              HostName = $VM.VMhost
              Cluster = $cluster
            }
        $report += $object
        }

    }
    }
}
$report | Export-Csv C:\Temp\VMs.csv -NoTypeInformation -UseCulture

If you only want to shared data warehouses you can then use

$datastores = $cluster | Get-VMHost | Get-Datastore | Where {$_.Extensiondata.Summary.MultipleHostAccess -eq $True}

Hope this helps

Tags: VMware

Similar Questions

  • How to list all files within a data store and sent an email...

    Hello

    I know that within a data store there of are VM, but these virtual machines are right files?

    Some might create a virtual machine, remove the inventory but do not delete the folder/VM from the data store.

    Is thre anyway to get a script to list all records, not VM. s within a data store and be able to send emails?

    Thanks for your help,

    How about something like this:

    $VIServer = "YourVIServer".

    $EmailFrom = "Sender@Email".

    $EmailTo = "Recipient@Email".

    $Subject = "email subject".

    $SMTPServer = "YourSMTPServer".

    SE connect-VIServer $VIServer

    $datastores = get-Datastore

    {Foreach ($datastore to $datastores)

    $msg = "' nFolders in Datatore:"+ $datastore. " Name + "' not n".

    New-PSDrive-location $datastore - PSProvider data store name - VimDatastore-root '-' | Out-Null

    $folders = get-ChildItem Datastore:------|? {$_. ItemType - eq "File"}

    Remove-PSDrive Datastore. Out-Null

    {Foreach ($folder in $folders)

    $msg = "' t ' + $folder. Name + "' n '.

    }

    }

    Send-MailMessage-to $EmailTo - of $EmailFrom - $msg - SmtpServer $SMTPServer body-subject $Subject

    Disconnect-VIServer-confirm: $false

    This will send an email with an output similar to the following:

    Files in Datatore: local-esx100

    Test-VM

    ARandomFolder

    MoreFolders

    Files in Datatore: local-esx101

    Test-VM2

  • Create a script to list all the .bat and .cmd files with the dir command &

    Hello

    Im trying to create a script that will list all the .bat and .cmd files in a specific folder and add the data to a new file (file.txt) - example below:

    dir c:\>desktop\file.txt/OD
    dir d:\>>desktop\file.txt
    dir f:\jobs\*.bat>>desktop\file.txt/OD

    IM able to search the F drive and the list of all the .bat files using a generic parameter, but ideally id like to search for .bat and .cmd files, but whenever I have it try does not work. Any ideas?

    I tried the following:

    dir c:\>desktop\file.txt/OD
    dir d:\>>desktop\file.txt
    dir f:\jobs\*.bat,*.cmd>>desktop\file.txt/OD

    Any help is appreciated, the reason for which I need to check all the .bat and .cmd files is to ensure that the scripts on a cluster are all data, so need them all listed in a doc if possible

    Thank you

    Hello

    Thank you for visiting the Microsoft answers community site. Your question of Windows 7 is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for guys official script Forum. Please ask your question in the official Scripting Guys Forum.

    http://social.technet.Microsoft.com/forums/en-us/iTCG/threads

  • Trying to create a script that lists all clusters in a data center

    Hello

    I am trying to create a script that exports a vCenter configuration essentially and imports it in a new vCenter. I want the script to run without specifying a center of data manually. All the scripts I've seen you need to manually enter the data center.

    So, how to do a list of all the data centers with clusters in each of them? I also want to create a variable that contains the groups for the respective data centers. Here's a basic idea of what I want to do:

    $Datacenters = get-data center

    foreach ($Datacenter to $Datacenters)

    {

    $cluster = get-Cluster-location $Datacenter

    Write-Host "list of clusters in $Datacenters.

    Write-Host "$Cluster".

    }

    Who will give me the output like this:

    List cluster Datacenter1

    cluster2 CLUSTER1

    List cluster Datacenter2

    cluster3 cluster4

    But I don't know how I can get so I have variable like this:

    $datacenter1 = cluster1, cluster2

    $datacenter2 = cluster3, cluster4

    Did you mean something like this?

    Get-data center | %{

    New-Variable - Name $_. Name - value ([string]: join ("," (Get-Cluster-location $_ | % {$_.}))) Name})))

    }

  • Script to list all the VMS and their scsi controller

    Hey guys,.

    New to scripting and my boss is looking for me to get a list of all the vm in our environment and the type of scsi controller they have. It seeks to go to paravirtual controller and need to know what vm, he needs to hit. I saw there is a script to change the paravirtual but he won't do it again, just the list including vm has what. Any help would be greatly appreciated.

    Thank you

    Rich

    Something like that?

    Get-VM | Select Name,@{N="Controller Type";E={Get-ScsiController -VM $_ | Select -ExpandProperty Type}}
    
  • PowerCLI script to list all the material

    Greetings,

    I'm looking for a script that will display all the material parameters for disk including my vm, USB, series and parallel ports, etc...

    Found this script for serial ports:

    $vms = get - VM

    {foreach ($vm to $vms)

    Notice-EEG - ViewType VirtualMachine. %{

    if($_.) Config.Hardware.Device | where {$_.} GetType(). Name - eq

    {'VirtualSerialPort'})

    $_. Name

    }

    }

    }

    However how to change it for all material or I need to specify each potential device?  How can I get a list of options, for example, where I find that 'VirtualSerialPort' is an option?

    Also how I got out to a csv file.

    Try this

    Get-View -ViewType VirtualMachine | %{
         $vm = $_
         $_.Config.Hardware.Device | Select @{N="VM name";E={$vm.Name}},@{N="HW name";E={$_.GetType().Name}},@{N="Label";E={$_.DeviceInfo.Label}}
    } | Export-Csv "C:\VM-HW.csv" -NoTypeInformation
    

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • PowerCLI script to list all the streams

    Hello

    Want to know if there is a way to list all inbound and outbound connections with IP and port of a vcenter infrastructure.

    Try it with scale and dvs but looks delicate, as navigator of Vmware infrastructure can perhaps do.

    But for sure, I think we can do it with powercli just want to confirm if there already exists.

    Thank you!

    Hello

    Check if that shell commands can help you

    https://KB.VMware.com/kb/2051814

    https://KB.VMware.com/kb/2020669

    Or with (command shell and PowerCli)

    http://technodrone.blogspot.com/2011/09/netstat-for-ESXi.html

    I hope this can help

  • Script to create multiple [pooled VM specified data store and resources

    I tried to make the following... writng a powershell script to perform the following operations

    (1) create a resource pool named reservedly set to unlimited

    (2) create 4 Virtuall machines in the yellow resource pool named DB-yellow, yellow-APP1, App2-yellow and yellow-bk

    Yellow-DB

    Yellow-App2, App1-yellow and yellow-bk

    (3) Vrtual all machines must be created in the Datastore YELLOW-OS

    (5) Yellow_DB shoule have a second virtual 8 GB of drive size in the YELLOW-PF data store

    Yellow-App1, App2-yellow and yellow-bk should all have a second virtual 5GB drive size in the YELLOW-PF data store

    Any ideas?

    Kind regards

    (1) create a virtual computer

    Hi Gboskin,

    Take a look at the following doc:

    http://communities.VMware.com/docs/doc-6972

    The script can deploy vm in resourcepools, clusters and on esx hosts. You can specify warehouses of data, ip etc.

    On the site of the doc, I have an older version of the script, I will update as soon as possible.

  • PowerCLI Script required to identify all clusters in a data center and all hosts within each cluster and calculate it using cpu and ram, avg, min, and max.

    Hi all

    I'm new to powercli and try to create a script to list all clusters in a data center and all hosts in a cluster and calculate min, max and avg cpu usage and ram by the host and cluster. So far, I have tried the below but I can't publish the results of my script.

    $Function = @)
    ForEach ($DataCenter Get-Data Center)
    {
    ForEach ($cluster in ($DataCenter |)) Get - Cluster)) - need help to post the information here and confirm if this is correct or not.
    {
    ForEach ($hosts in ($cluster |)) Get - VMHost))
    {
    ForEach ($vms to ($hosts |)) Get - VM)) - do not know if I called you here functions properly
    {
    $allvms = @)
    $allhosts = @)
    $hosts = get-VMHost
    $vms = get - Vm

    {foreach ($vms in $hosts)
    $hoststat = "" | Select the host name, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin
    $hoststat. Host name = $vmHost.name

    $statcpu = get-Stat-entity ($vmHost) - start (get-date). AddDays(-30)-Finish (Get-Date) - MaxSamples 10000 - stat cpu.usage.average
    $statmem = get-Stat-entity ($vmHost) - start (get-date). AddDays(-30)-Finish (Get-Date) - MaxSamples 10000 - stat mem.usage.average

    $cpu = $statcpu | Measure-object-property value - average - Maximum - Minimum
    $mem = $statmem | Measure-object-property value - average - Maximum - Minimum

    $hoststat. CPUMax = $cpu. Maximum
    $hoststat. CPUAvg = $cpu. Average
    $hoststat. CPUMin = $cpu. Minimum
    $hoststat. MemMax = $mem. Maximum
    $hoststat. MemAvg = $mem. Average
    $hoststat. MemMin = $mem. Minimum
    $allhosts += $hoststat
    }
    }
    }
    }
    }

    $Function | Select the host name, MemMax, MemAvg, MemMin, CPUMax, CPUAvg, CPUMin | Export-Csv "c:\Function.csv" - noTypeInformation

    Any help on this is much appreciated.

    [Ordered] casting was introduced in v3 PowerShell.

    For PowerShell v2, you can use

    $vms = get - VM

    $stat = 'cpu.usage.average ','mem.usage.average '.

    $start = (get-Date). AddDays(-31)

    $report = get-Stat-entity $vms - start $start - Stat $stat - ErrorAction SilentlyContinue |

    Group-object - property {$_.} @entity.name} | %{

    $cpu = $_. Group | where {$_.} MetricId - eq "cpu.usage.average"} | Measure-object-property value - average - Maximum - Minimum

    $mem = $_. Group | where {$_.} MetricId - eq "mem.usage.average"} | Measure-object-property value - average - Maximum - Minimum

    New-object PSObject-property @ {}

    Datacenter = Get-Datacenter - VM $_. Group [0]. Entity | Select the name of ExpandProperty-

    Cluster Cluster Get - VM = $_. Group [0]. Entity | Select the name of ExpandProperty-

    VMHost = $_. Group [0]. Entity.Host.Name

    Name = $_. Group [0]. @entity.name

    CpuMin = $cpu. Minimum

    CpuAvg = $cpu. Average

    CpuMax = $cpu. Maximum

    MemMin = $mem. Minimum

    MemAvg = $mem. Average

    MemMax = $mem. Maximum

    }

    }

    $report | Sort-Object-property Datacenter, Cluster, VMHost name |

    Export Csv report.csv - NoTypeInformation - UseCulture

  • Need a PowerShell Script to list all my stores of data, capacity and VMFS format.

    All,

    I need a script to list all my stores of data, capacity and VMFS format.

    That's what I have so far but its does not give me the results I need.

    Get-Datastore - Datacenter MN_PROD | where {$_.} Type - eq "VMFS"} | Select-Object Name,@{N="VMFS version. {E = {$_.Info.Vmfs.Version}}

    Try like this

    Get-Datastore -Datacenter MN_PROD | where {$_.Type -eq "VMFS"} | Select-Object Name,CapacityGB,    @{N="VMFS version";E={$_.FileSystemVersion}}
    
  • How to list all the tables that have no data

    Hi all


    I want to list all the tables that have no data. (registration number is 0)

    Someone help me.

    Thank you
    Thiensu2810

    Select owner, table_name from dba_tables where num_rows = 0;

    This assumes that the table statistics are COMMON.

  • y at - it a web page that lists all the supported versions of Firefox?

    We wish to state our user doc recommended Firefox versions. So it is the web page that lists all the supported versions of Firefox and can also, we have a list of dates to drop support for versions currently supported?

    Yes, it has changed a bit since this thread was started 9 months ago. Support for Firefox 3.6.x continues and versions 4 + lose support at the next new version is available. Support for Firefox 7 ended when Firefox 8 came out yesterday 11 / 08.

    Support for 3.6.x will likely end early next year when the proposed new ESR (Extended Support Release) comes to massive institutional facilities / corporate. ESR is proposed for a week 42 version support cycle timetable of a 'standard' of the week quick release 6.

  • Can I program a script to remove all the ISOs datastore on all virtual machines?

    I found a "bug" that if backupexec creates a backup of a computer virtual with a mounted ISO, you can not restore VM to a different host, even after that another backup ran again with the ISO is more fitted. SO whether a backup runs on Monday night with an ISO mounted from the data store and I'm going to come in and chop the ISO and Tuesday backup runs that always, I can not restore the backup from Tuesday to a different host. Also, I should mention that these hosts do not share no matter what storage between them and I can restore to the host of origin without any problem. I'm working on that symantec, but it seems to me that the best response is no, not an ISO mounted when the backup starts, but I can easily predict that sometimes in the life of our environment that someone leaves an ISO mounted so I'll try to find a medium schedule a script that will remove all ISOs mounted in virtual machines. There is a work around by removing the virtual machine in the inventory and recreate the virtual machine with the existing VMDK file, it means having to stop this server whenever someone does this. Any help would be greatly appreciated.

    the script would look like below.

    Connect-VIServer myvcenter.yourdomain.com get-cddrive -VM * |where {$_.ISOPATH -ne $null}|set-cddrive  -nomedia Disconnect-VIServer -Confirm:$false
    
  • Warehouses of data, ScsiLuns, and the VI-plugin (c#)

    Hello

    I'm writing a VI - Plugin (vmware infrastructure client version 2.5.0)

    I'm a little stuck trying to decode the API...

    I'll try to find the relationship between a data store ("DS_1" in the attached JPG) and the ScsiLun ("vmhba2:6:1:1" in the attached JPG)

    what I found so far:

    I can find the host

    Vmomi.HostSystem host = Service.ManagedObjectIdentifiedBy [suid] like Vmomi.HostSystem;

    I can also find the data store

    Vmomi.Host.DatastoreBrowser ds = host. GetDatastoreBrowser();

    Vmomi.DatastoreArray dsa is ds. GetDatastore();

    now dsa. GetInfo(). Name could give me a name ("DS_1 or DS_2 or DS_3')

    find the ScsiLun is also simple:

    Vmomi.Host.ConfigManager cm = host. GetConfigManager();

    Vmomi.Host.StorageDeviceInfo sdi = cm. StorageSystem.GetStorageDeviceInfo ();

    //now sdi. ScsiLun. CanonicalName would give me a Lun (vmhba2:6:2:1 or vmhba2:6:1:1 or vmhba2:6:3:1)

    I'll try to find what connects these 2 bays (warehouses of data and ScsiLuns)

    Thank you

    Gil.

    He is buried a little, but it's in DatastoreInfo property.  You must list your data warehouses, get each property of the info .  Then test that it is an object of VmfsDatastoreInfo .  You will then need to enumerate the properties of the vmfs.extent table (maybe only 1 if no extensions) for the diskName property.

    This should match canonicalName in scsiLun.

    I have a few undocumented Perl code if you are interested which shows how I did it.   Let me know if it helps, I'll post it.

  • List all the songs?

    Hi, I have a quick beginner question:

    I just finished all my music on my new SanDisk Sansa clip + loading, and I've encountered a problem. In the individual sections for each of the artists, there seems to be no way to list all of the songs from this particular artist in my library. Instead, there are only folders for each album and the "Play All" option. Now if I want to play a song in particular of this artist, I have to go to the respective album folder and select the song. It works fine if I remember the album for every song I want to play, but if I don't remember, I go through each folder.

    What I saw before with portable mp3 players is a way to list all of the songs from a particular artist in alphabetical order, regardless of the album sound in. Is it possible to do this with my device? I've been looking in the menus on the camera itself and on this forum, but so far without success.

    Thank you!

    You can see all the songs by an artist when choosing the artist, play together, and then pressing the button at 6 oclock and choosing back to the music list. The song list will however in alphabetical order. They will be in order, based on the album order, IE. first albumm 1 (based on the number of track), the song2 song, song 3,... Finally, the second song on the album 1, 2, song etc.

    Would be nice if they could be presented in alphabetical order. I guess as a workaround you could try to put all the songs by an artist in one folder, then by browsing the folder using music files. Lists all the songs by an artist alphabetically (asuming the file name is the name of the song). I guess this could become unmanigable but when you have a large number of songs of an artist. Having too many songs in a single folder can bog down the player.

Maybe you are looking for