Script to get the tree of data center
Hi all
I want to return a complete tree of data through script task centers.
example:
Datacenter1:
CLUSTER1:
Host1:
Host2:
VM1:
VM2
When I try to enumerate the data center to get this Cluster fails. Can anyone help on this?
MyScript:
var myDatacenters = VcPlugin.getAllDatacenters ();
for each (i = 0; i < myDatacenters.length; i ++)
{
for each (mycluster in myDatacenters [i] .cluster)
{
System.Debug (cluster. (Name)
for each (myHostSystem to myCluster.host)
{
System.Debug (myHostSystem.Name);
for each (myVMs to myHostSystem.vm)
{
if(myVMs.isTemplate==true)
{
System.Debug (myVMs.Name);
}
}
}
for each (myDatastore to myCluster.datastore)
{
System.Debug (myDatastore.Name);
mytotalDatastoreCapacity += myVcDatastore.summary.capacity;
mytotalDatastoreFreeSpace += myVcDatastore.summary.freeSpace;
}
}
}
Hi LuckyT,
There is no attribute VcDatacenter.cluster, you could use VcPlugin.getAllClusterComputeResources () instead.
But I found a code on my environment facing maybe also your needs:
for each ( var myDatacenter in VcPlugin.allDatacenters ) { forEachChildEntity ( myDatacenter ); } function forEachChildEntity( myChildEntity ) { switch ( true ) { case myChildEntity instanceof VcDatacenter: System.log( "Datacenter:" + myChildEntity.name ); for each ( var myChildEntitysChildEntity in myChildEntity.hostFolder.childEntity ) { forEachChildEntity( myChildEntitysChildEntity ); } for each ( var myChildEntitysChildEntity in myChildEntity.datastoreFolder.childEntity ) { forEachChildEntity( myChildEntitysChildEntity ); } for each ( var myChildEntitysChildEntity in myChildEntity.networkFolder.childEntity ) { forEachChildEntity( myChildEntitysChildEntity ); } for each ( var myChildEntitysChildEntity in myChildEntity.vmFolder.childEntity ) { forEachChildEntity( myChildEntitysChildEntity ); } break; case myChildEntity instanceof VcFolder: System.log( "Folder:" + myChildEntity.name ); for each ( var myChildEntitysChildEntity in myChildEntity.childEntity ) { forEachChildEntity( myChildEntitysChildEntity ); } break; case myChildEntity instanceof VcClusterComputeResource: System.log( "Cluster:" + myChildEntity.name ); for each ( var myChildEntitysChildEntity in myChildEntity.resourcePool.resourcePool ) { forEachChildEntity( myChildEntitysChildEntity ); } break; case myChildEntity instanceof VcResourcePool: System.log( "ResourcePool:" + myChildEntity.name ); for each ( var myChildEntitysChildEntity in myChildEntity.resourcePool ) { forEachChildEntity( myChildEntitysChildEntity ); } break; case myChildEntity instanceof VcVmwareDistributedVirtualSwitch: System.log( "DV Switch:" + myChildEntity.name ); for each ( var myChildEntitysChildEntity in myChildEntity.portgroup ) { forEachChildEntity( myChildEntitysChildEntity ); } break; case myChildEntity instanceof VcDistributedVirtualPortgroup: System.log( "Portgroup:" + myChildEntity.name ); break; case myChildEntity instanceof VcStoragePod: System.log( "StoragePod:" + myChildEntity.name ); break; case myChildEntity instanceof VcVirtualMachine: System.log( "VirtualMachine:" + myChildEntity.name ); break; default: System.log( "Unknown:" + myChildEntity.name ); break; } }
Kind regards
Chris
Tags: VMware
Similar Questions
-
need a script to get the news of VMs who believed map
Hi guys
I need a script to get the info of VMs who believed the data center map...
Like this
name of the virtual machine
name of the cluster
ESXi host ip
name of the disk... (if it is disk 1 or 2)
name of the data store
NNA
I used the script below, but I am unable to store data name, cluster and host Info
Get
-VM
| Get
-HardDisk
-DiskType
"RawPhysical"
,
"RawVirtual"
|
Select
Parent,Name,DiskType,ScsiCanonicalName,DeviceName |
fl
Please suggest any modified script to get above information..
Try like this
Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" |Select Parent,Name,DiskType,ScsiCanonicalName,DeviceName, @{N="Datastore";E={$_.Filename.Split(']')[0].TrimStart('[')}}, @{N="VMHost";E={$_.Parent.Host.Name}}, @{N="Cluster";E={Get-Cluster -VM $_.Parent | Select -ExpandProperty Name}}
-
Get - vm with location data center column
How can I get info VM with data center location included in a column?
I check $_Extensiondata.config and do not get it down there
Try this:
Get - VM $vm | Format-table name,
@{Name = 'Center'; Expression = {$_.vmhost.parent.parentfolder.parent}; a = 'center'} - a
Tested with a virtual machine in a host of 'group '. I think that this may change if the host is not in a Cluster.
Hope this works
-
ETA App should help to get the time and date feature HELP!
Hi everyone, I'm doing an application where I need to get the time and date of the antone device can help, I know there is a function such as getDate or getTime but im not to know how to use it.
As far as I know,
I use this to get the time system (it returns long type)
System.currentTimeMillis();
After that, you can use SimpleDateFormat to convert date and time
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm"); String time = sdf.format(new Date(System.currentTimeMilis()));
-
Can write us "PowerCLI Script" to get the details of card RAID HP (Firmware & Driver)
For example: native ESX command below shows desired output for me.
But we needed equality PowerCLI ESX command below script
# cat/proc/driver/cciss/cciss0
cciss0: HP Smart Array P400i controller
Board ID: 0x3235103c
Firmware version: 7.22# cat/proc/driver/hpsa/hpsa0
hpsa0: HP Smart Array P410i controller
Board ID: 0x3245103c
Firmware version: 5,70
Driver version: HP HPSA driver (v 5.0.0 - 17vmw)
The extracted following PowerCLI you will get server and type of controller, firmware version and the hpsa/Smart Storage Array controllers driver version based of:
Get-VMhost | Sort | Select Name, Model,@{N='Controller Type'; E={(Get-VMHostHba -VMHost $_ | ? {$_.Model -imatch '.*(hpsa|smart).*'}).Model}},@{N='Controller Firmware'; E={($_.ExtensionData.Runtime.HealthSystemRuntime.SystemHealthInfo.NumericSensorInfo | ? {$_.Name -like '*hpsa*firmware*'}).Name}},@{N='hpsa Driver Version'; E={($_.ExtensionData.Runtime.HealthSystemRuntime.SystemHealthInfo.NumericSensorInfo | ? {$_.Name -like '*scsi-hpsa*'}).Name}} | Format-Table -Autosize
The sample output:
Name Model Controller Type Controller Firmware hpsa Driver Version---- ----- --------------- ------------------- -------------------esxihost1022.local ProLiant DL380 G6 Smart Array P410i HP Smart Array Controller HPSA1 Firmware 6.40 Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1023.local ProLiant DL380 G6 Smart Array P410i HP Smart Array Controller HPSA1 Firmware 6.40 Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1024.local ProLiant DL380 G6 Smart Array P410i HP Smart Array Controller HPSA1 Firmware 6.40 Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1033.local ProLiant DL360p Gen8 Smart Array P420i HP Smart Array Controller HPSA1 Firmware 5.42 Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1034.local ProLiant DL360p Gen8 Smart Array P420i HP Smart Array Controller HPSA1 Firmware 5.42 Hewlett-Packard scsi-hpsa 5.0.0.60-1OEM.500.0.0.472560 2014-05-15 15:32:23.000esxihost1041.local ProLiant DL380 G5 Smart Array P400 HP Smart Array Controller HPSA1 Firmware 7.24 VMware scsi-hpsa 5.0.0-17vmw.500.0.0.469512 2011-08-19 01:58:59.000esxihost1042.local ProLiant DL380 G5 Smart Array P400 HP Smart Array Controller HPSA1 Firmware 7.24 VMware scsi-hpsa 5.0.0-17vmw.500.0.0.469512 2011-08-19 01:58:59.000esxihost1160.local ProLiant BL460c Gen8 Smart Array P220i HP Smart Array Controller HPSA1 Firmware 5.22 Hewlett-Packard scsi-hpsa 5.0.0-40OEM.500.0.0.472560 2012-08-24 21:04:51.000esxihost1161.local ProLiant BL460c Gen8 Smart Array P220i HP Smart Array Controller HPSA1 Firmware 5.22 Hewlett-Packard scsi-hpsa 5.0.0-40OEM.500.0.0.472560 2012-08-24 21:04:51.000
-
How can I get the list of data stores in a cluster data store?
How can I get the list of data stores in a cluster data store? I mean the command line option.
Hello
by command line, you mean PowerCLI?
If so, you can display data with this warehouses:
Get-DatastoreCluster-name DSClustername | Get-Datastore
Tim
Edit: Moved the thread to the PowerCLI community
-
Script to get the name of VMhost among a list of VM?
Hi people,
Can anyone here help me scripting by getting the ESXi host name or $vmhost name in the list of the VM?
Thank you.
You mean this
Get-VM | Select Name,@{N="Host";E={$_.Host.Name}}
-
I'm new in indesign scripting, please tell me how to write a script to get the contents of an XML element and then sort all the content
Hello
Can the code below is useful for you, but I do not know how to sort.
Change the tag based on your employment application.
-
script to get the csv vm disk usage and export to csv format
Hi all
I am trying to create a script to get the use of disk for vm - space - free space and total disk space.
I used this script that allows me to get the required result.
but I need to edit the script for each cluster, VM he should get computers virtual cluster and check the vm disuage. and export of csv file
$vms = import-CSV "C:\Cluster.csv".
$outputfile = "c:\Diskusage.csv".
SE connect-viserver VC-vcadmin username-password
{foreach ($vm to $vms)
Get - VM $vm.name | Where {$_.} PowerState - eq "Receptor"} | Get-VMGuest | Select the ExpandProperty - VMName disks | Select VMName, path, @{Name = "DiskCapacityGB"; Expression = {[math]: Round ((($_.))} {{((Ability) / 1 GB), 2)}}, @{Name = "DiskUsedMB"; Expression = {[math]: Round ((($_.))} Capacity - $_. {{((FreeSpace) / 1 MB), 2)}}, @{Name = "DiskFreeMB"; Expression = {[math]: Round ((($_.))} {{((FreeSpace) / 1 MB), 2)}} | Export-Csv - NoTypeInformation $outputfile}
Viserver disconnect
Joint the output file
Veuileez help me in creating the script
You can try like this?
Connect-viserver VC -user vcadmin -password foreach($cluster in Get-CLuster){ $outputfile = "c:\" + $cluster.Name + "-Diskusage.csv" Get-VM -Location $cluster | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VMName -ExpandProperty Disks | Select VMName, Path, @{Name="DiskCapacityGB";Expression={[math]::Round((($_.Capacity)/1GB),2)}}, @{Name="DiskUsedMB";Expression={[math]::Round((($_.Capacity - $_.FreeSpace)/1MB),2)}}, @{Name="DiskFreeMB";Expression={[math]::Round((($_.FreeSpace)/1MB),2)}} | Export-Csv -NoTypeInformation $outputfile} Disconnect-viserver
The script creates a CSV file for each cluster.
-
How can I get the time and date appears on a sony cyber-shot camera
How can I get the time and date appears on a sony cyber-shot camera
Hi terpmarty,
What is the model number of the Sony Cybershot camera?
Instructions for superimposing the date and time are model specific. Some models do not have the ability to superimpose the date and time too. In such a case, you can use the supplied software Picture Motion Browser (PMB) or PlayMemories home (WPH) (Compatible with the Windows operating system) to print the date and time on pictures. -
When the research report I get the message "no data found".
When I run a search on one of the fields of research, I get the message "no data found". Anyone can help me to understand what it is that I don't hurt or not done? Thank you
Deanna
http://Apex.Oracle.com/pls/OTN/f?p=4550:1:4031563210204584
Workspace: DEANNA2
Username: DDOVE@KHP. KS.GOV
Password: Dclipse03
Page 21No, I added a calculation to the page to see what is the sql code that is returned by the function... Now, I could add in another column and see what happens...
That's why I suggested moving it to a function outside the page... You can test this in the sql command window and the prefect what you are after... Have done reports a little like this... Or even more fun, with a function in the pipeline...
Thank you
Tony Miller
Webster, TX -
Script to get the ID of the new LUN to create the data store
Forgive the question from a novice - I'm not a developer at all.
I am trying to write a script that will create a data store on a new iSCSI LUN - the problem is that I have already several other LUNS with the warehouses of data on it, so after I refresh the HBA, basically need to understand is that the new LUN and create a store of data on it.
I made all sorts of googling and found scripts to create a new store database, but only in the first store of data on a new iSCSI target.
Any help would be appreciated.
Thank you!
You can try the first script of Arnim in list HBA WWPN and LUN using Powershell
-
Script to get the disk and LUN informaiton
Hi all
I have the list of virtual machines on servers different vCente and I need to get the disk and LUN information for the list of virtual machines.
Help me build the script?
Kind regards
Vijay
$Information = @)
$Vminfo = get - VM | Select-Object *, @{N = "Hard drives"; E={$_ | Get-HardDisk}}, @{N = "HDDcount"; E={($_ | (Get-harddisk).length}}
$vmlist = $Vminfo | Sort-Object-down HDDcount
{foreach ($vm to $vmlist)
#$Harddiskinfo = $vm | Get-hard drive
$props = new-Object PSObject
$props | Add-member-name "Folder" - Membertype NoteProperty-value $vm.folder
$props | Add-member-name "VMName" - Membertype NoteProperty-value $vm. Name
$props | Add-Member-name "vCPUs" - Membertype NoteProperty-value $vm. NumCpu
$props | Add-member-name "Memory (GB)" - Membertype NoteProperty-value $vm. MemoryGB
$DiskNum = 0
foreach ($hdd in $vm. Hard drives) {}
$controllerinfo = $hdd. ExtensionData
$datastoreName = $($hdd.) Filename.Substring (1) - split ("]" ")) [0]
$datastoreinfo = get-$datastoreName data store
$controllerkey = $controllerinfo.controllerkey.tostring)
$keycount = ($controllerkey |) measure-object-character | Select-Object - expandproperty Characters) m:System.NET.SocketAddress.ToString)
$virtualID = "{0}: {1}: {2} ' f $controllerkey.substring (0,1), $controllerkey.substring ($keycount - 1), $hdd. ExtensionData.Unitnumber
$props | Add-Member-name "Disk scsiID$ ($DiskNum) '-Membertype NoteProperty-value $virtualID
$props | Add-member-name "$($DiskNum) hard disk drive"-Membertype NoteProperty-value $hdd. Name
$props | Add-member-name "Disk$ ($DiskNum) Size (GB)"-Membertype NoteProperty-value $hdd. CapacityGB
$props | Add-member-name "$($DiskNum) DatastoreName disc"-Membertype NoteProperty-value $datastoreName
$props | Add-member-name "$($DiskNum) DatastoreSize disc"-Membertype NoteProperty-value $datastoreinfo. CapacityGB
$props | Add-member-name "$($DiskNum) DatastoreFreeSpace disc"-Membertype NoteProperty-value $datastoreinfo. FreeSpaceGB
$DiskNum ++
}
$Information += $props
}
$Information | Out-GridView
-
Hello
Need help to get the script of ' Script for the VLan ID, vSwitch, networking and group ports vmkernel of vCenter. "to CSV
Any help will be much appreciated.
Get-VMHost | {foreach}
$vmhost = $_
$PortGroups = $vmhost | Get-VirtualPortGroup
$vSwitchs = $vmhost | Get-VirtualSwitch
$pNic = $vmhost | Get-VMHostNetworkAdapter
$Managementinfo = $pNic | Where-Object {$_.} ManagementTrafficEnabled - eq $true}
$vMotioninfo = $pNic | Where-Object {$_.} VMotionEnabled - eq $true}
$FTinfo = $pNic | Where-Object {$_.} FaultToleranceLoggingEnabled - eq $true}
$vlanID = $PortGroup | Where-Object {$_.name - eq $Managementinfo.ExtensionData.spec.Portgroup} | Select-object - ExpandProperty VLanId
{foreach ($PG in $PortGroups)
#Management Info network
If ($Managementinfo.PortGroupName - eq $PG.) {Name)
$MGMTStatus = "enabled".
$ManagementIP = $Managementinfo | Where-Object {$_.} PortGroupName - eq $PG. Name} | Select-Object - ExpandProperty IP
}
else {}
$MGMTStatus = "Disabled".
$ManagementIP = $null
}
#vMotion Info network
If ($vMotioninfo.PortGroupName - eq $PG.) {Name)
$vmotionStatus = "enabled".
$vMotionIP = $vMotioninfo | Where-Object {$_.} PortGroupName - eq $PG. Name} | Select-Object - ExpandProperty IP
}
else {}
$vmotionStatus = "Disabled".
$vMotionIP = $null
}
#FT Info network
If ($FaultToleranceLoggingEnabled.PortGroupName - eq $PG.) {Name)
$FTStatus = "enabled".
$ftIP = $FTinfo | Where-Object {$_.} PortGroupName - eq $PG. Name} | Select-Object - ExpandProperty IP
}
else {}
$FTStatus = "Disabled".
$ftIP = $null
}
#vmKernel name
$VMKernel = $pNic | Where-Object {$_.} PortGroupName - eq $PG. Name} | Select-Object - ExpandProperty DeviceName
$result = "" | Select-Object HostName, vSwitchName, PortGroupName, VLanID, ManagementTraffic, ManagementIP, vMotionTraffic, vMotionIP, FTTraffic, FTIP, VMKernel
$result. Host name = $vmhost.name
$result.vSwitchName = $PG. VirtualSwitchName
$result. PortGroupName = $PG. Name
$result. VLanID = $PG. VLanID
$result. VLanID = $PG. VLanID
$result. ManagementTraffic = $MGMTStatus
$result. ManagementIP = $ManagementIP
$result.vMotionTraffic = $vmotionStatus
$result.vMotionIP = $vMotionIP
$result. FTTraffic = $FTStatus
$result. FTIP = $ftIP
$result. VMKernel = $VMKernel
$result
}
} | Export-Csv c:\temp\data.csv
-
Groovy Script to find the difference between Dates
I am trying to build a script that takes a date from a RequestField and calculates the number of days between this date and the current date (from session).
So far, I have a problem, the analysis to-date from the RequestField chain. I found this code but it doesn't seem to work...
date = new Date().parse('yyyy/MM/dd', '1973/07/09')
I get the following error...
Error Message: groovy.lang.MissingMethodException: No signature of method: java.util.Date.parse() is applicable for argument types: (java.lang.String, java.lang.String) values: {"yyyy/MM/dd", "1973/07/09"}
Any help would be greatly appreciated.
Hello
What version of server? The extract you have here works fine on mine (563).
This also works for me
new java.text.SimpleDateFormat('yyyy/MM/dd').parse('1973/07/09')
See you soon
Nils
Maybe you are looking for
-
How can I turn off the tiny icons next to the URL in my bookmarks menu?
My question says it all. Thank you.
-
Printing from Android at HP6520
I loaded HP eprint app on Samsung galaxy 10.1 and printed on a printer to my son's House. When I try to print on my printer, it recognizes the printer and its IP address, but the 'print' button is faded and unresponsive. The printer works wirelessly
-
Transfer files of Microsft money 7-Microsoft Money Plus Sunset Deluxe
I use Microsoft Money 7 on a laptop very old (more than 8 years) using Windows XP and I recently got a newer, faster laptop using Windows 7 I just install Microsoft Money Plus Sunset Deluxe on. My question is how can I move all my files in Money 7 to
-
PowerShot HS XS530: Filter size? An adapter is required? Model number?
What size filter does the XS530? An adapter is needed to fix a filter? If Yes, what is the model of the adapter number? Thank you!
-
Preferences for files of the menu drop-down
In some programs, the drop-file keeps a history of the previously opened file. Is it possible to make it NOT it?