Find records VM size and export to csv format
Hello
I need this script to export to csv format, but I have problems to make it work.
Notice-EEG - ViewType VirtualMachine-property name, Config.Hardware.Device, LayoutEx | %{
$viewVM = $_; $viewVM.Config.Hardware.Device |? {$_-is [VMware.Vim.VirtualDisk]} | %{
# for each device VirtualDisk, get some info
$oThisVirtualDisk = $_
# get the disk element LayoutEx, which corresponds to the VirtualDisk
$oLayoutExDisk = $viewVM.LayoutEx.Disk |? {$_. {Key - eq $oThisVirtualDisk.Key}
# get the FileKeys that correspond to the LayoutEx-> sort items of this VirtualDisk
$arrLayoutExDiskFileKeys = $oLayoutExDisk.Chain |? {$_-is [VMware.Vim.VirtualMachineFileLayoutExDiskUnit]}
New-Object PSObject-property @ {} TypeName
# Add the VM name
VMName = $viewVM.Name
# disc label, such as "disk 1".
DiskLabel = $_. DeviceInfo.Label
# the path to the data store for the file VirtualDisk
DatastorePath = $_. Backing.FileName
# the size provisioned to the VirtualDisk
ProvisionedSizeGB = [Math]: tour ($_.) CapacityInKB / 1 MB, 1).
# Get the file LayoutEx elements that correspond to the FileKeys for this LayoutEx disk and the size for items that are "diskExtents" (retrieved in the form of bytes, so convert to GB)
SizeOnDatastoreGB = [Math]: round (($arrLayoutExDiskFileKeys | % {$_.)) FileKey} | % {$intFileKey = $_; $viewVM.LayoutEx.File |?} {($_. Eq - $intFileKey - button) and ($_.) Type - eq "diskExtent")}} | Measure - Object - size of the sum). Summary / 1 GB, 1).
} # end new object
} # end foreach-object
} # end external foreach-object
Capture all the output in a variable and send this variable in a CSV file.
Something like that
$result = Get-View -ViewType VirtualMachine -Property Name, Config.Hardware.Device, LayoutEx | %{ $viewVM = $_; $viewVM.Config.Hardware.Device | ?{$_ -is [VMware.Vim.VirtualDisk]} | %{ ## for each VirtualDisk device, get some info $oThisVirtualDisk = $_ ## get the LayoutEx Disk item that corresponds to this VirtualDisk $oLayoutExDisk = $viewVM.LayoutEx.Disk | ?{$_.Key -eq $oThisVirtualDisk.Key} ## get the FileKeys that correspond to the LayoutEx -> File items for this VirtualDisk $arrLayoutExDiskFileKeys = $oLayoutExDisk.Chain | ?{$_ -is [VMware.Vim.VirtualMachineFileLayoutExDiskUnit]} New-Object -TypeName PSObject -Property @{ ## add the VM name VMName = $viewVM.Name ## the disk label, like "Hard disk 1" DiskLabel = $_.DeviceInfo.Label ## the datastore path for the VirtualDisk file DatastorePath = $_.Backing.FileName ## the provisioned size of the VirtualDisk ProvisionedSizeGB = [Math]::Round($_.CapacityInKB / 1MB, 1) ## get the LayoutEx File items that correspond to the FileKeys for this LayoutEx Disk, and get the size for the items that are "diskExtents" (retrieved as bytes, so converting to GB) SizeOnDatastoreGB = [Math]::Round(($arrLayoutExDiskFileKeys | %{$_.FileKey} | %{$intFileKey = $_; $viewVM.LayoutEx.File | ?{($_.Key -eq $intFileKey) -and ($_.Type -eq "diskExtent")}} | Measure-Object -Sum Size).Sum / 1GB, 1) } ## end new-object } ## end foreach-object } ## end outer foreach-object $result | Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture
Tags: VMware
Similar Questions
-
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.
-
Reports on multiple virtual centers and export to CSV format
Everyone,
Does anyone know if possible a way for me to do the following in the following format.
Requirements:
(1) report on multiple virtual centers
(2) export results to CSV or Excel with a title between each virtual Center
(3) the need for Virtual Center Cluster belongs, name of the Cluster, host number of ESX and number of virtual machines. (Additional information can be added to the report later).
It would be not so hard if I could just connect and report on all virtual centers and my results to export in this way. However, each virtual server Center have a different purpose and that is how senior management wants to see the results.
For example:
VC3 VC1 and VC2 = service server environment
VC4 and VC5 VC6 = service Workstation environments
VC7 VC8 = environment of Cloud Computing Services
What I would do is:
(1) connect to the first 3 virtual centers and collect the above information.
(2) I would like to create a title in the CSV or Excel named 'Standard Server environment summary'
(3) then I would like to export these 4 columns with data for each cluster.
Cluster is managed by this Virtual Center, the name of the Cluster, number # VM and ESX host
I then unplug the 3 first virtual centres.
Next
(1) I would like to connect to the 3 next virtual centres
2) add to the previous CSV or Excel with a title 'desktop environment summary.
(3) export the same information as above in the CSV file
Any help would be greatly appreciated.
Try something like this
$vcenters = @{} $vcenters["Server Environment"] = @("VC1","VC2","VC3") $vcenters["Workstation Environment"] = @("VC4","VC5","VC6") $vcenters["Cloud Environment"] = @("VC7","VC8") Set-PowerCLIConfiguration -DefaultVIServerMode Single -Confirm:$false | Out-Null $vcenters.GetEnumerator() | %{ &{foreach($vc in $_.Value){ $currentvc = Connect-VIServer -Server $vc Get-Cluster -Server $currentvc | %{ New-Object PSObject -Property @{ "Cluster is managed by VC" = $currentvc.Name Cluster = $_.Name "# of ESX hosts" = @($_.ExtensionData.Host).Count "# of VM" = Get-View $_.ExtensionData.Host -Server $currentvc | %{@($_.Vm).Count} | Measure-Object -Sum | Select -ExpandProperty Sum } } }} | Select "Cluster is managed by VC",Cluster,"# of ESX hosts","# of VM" | Export-Xls -Path C:\report.xls -WorksheetName $_.Name Disconnect-VIServer -Server $currentvc -Confirm:$false}
You will have to render the Xls export function.
Simplest is to include in the script with the code above.
The name of the group is reflected in the name of the worksheet, having a separate line would be a little more difficult.
-
I have created a multi-page document in inDesign and exported in PDF format. The original file size is 13.27 mb. I used the command size reduced to 2.86 to the file to download on the internet. However, one of the images in the original pdf file does not appear in the smaller file. Can someone help me?
Try the PDF tool optimize.
-
Remove "<; div" Excel file when exporting to CSV format
Hello
I have a report has the following properties:
Export of reports
Activate the output CSV = > Yes
Bind the Label = > export to CSV format
but when I run the report and press the link, I get an excel sheet indicating the reeport data, but the problem is that the report began with
< div id = "report_11749113153378136_catch" >, Iam if you're wondering how to solve the problem.
Thank you
Abdul Alkhateeb
Published by: dtabed on March 18, 2009 07:58Hi Adam,.
What version of APEX are you running? I think that this has been fixed in 3.1.2. If you disable partial-page refresh, that should get rid of your problem.
Martin
-----
[http://apex-smb.blogspot.com/] -
Leading zeros and export to CSV
HelloI run a sql query for retrieving telephone numbers and when exporting to CSV 0 are deleted. I understand that this is a problem of excel formatting, however does it perform a work around in the SQL that can preserve the leading zeros when exporting to CSV?
sliderrules wrote:
The format of data is of type char
SELECT «=» | test ctelno
When they are copied to surpass the value bed = 0999 6767 in excel (including =)
You need double quotes
'="'|| c.ctelno |' » "
-
Output on screen and EXPORT. CSV
Hi all
Were the creation of scripts for some general tasks and I got a little confused on what is happening. I have two scripts that are output on the screen even with EXPORT. CSV commond to end. I get the output sent to the CSV fine and there is no obvious errors.
Any whay Idears, that this could happen? I can post my script if that helps.
Thank you
Phil
This is the line with only $objHba in it.
It will display the content of this variable to the screen.
# $vmlist = Get-VM $table = @() foreach ($vmhost in (Get-view -ViewType Hostsystem )) { foreach ($hba in ($vmhost.config.storagedevice.hostbusadapter | where {$_.PortWorldWideName})) { $objHba = "" | Select-Object Hostname,Device,Model,Driver,Pci,Wwpn $objHba.HostName = $vmhost.Name $objHba.Device = $hba.Device $objHba.Model = $hba.Model $objHba.Driver = $hba.Driver $objHba.Pci = $hba.Pci $objHba.Wwpn = "{0:x}" -f $hba.PortWorldWideName # $objHba $table += $objHba } } $table | Export-Csv $outputDir\data\$date.$viserver.$filename.csv -NoTypeInformation
BTW what is the first (of line) doing here? It has nothing to do with the rest of the script.
Copy & paste mistake I guess?
____________
Blog: LucD notes
Twitter: lucd22
-
Find records overlapping start and end dates
Hi all
I have a table with begin and end date columns. I need to find the records that overlap with a few values in corresponding column.
Table: MG_AUTH_AGNT
-----
ID
MGATH_clnt
MGATH_beg_DT
MGATH_END_DT
MGATH_SERV_GRP
MGATH_STAT
MGATH_TYP
MGATH_NHIC_ERR_CD
-----
I need to find records containing dates that overlap.
Examples of data
-----
If the customer has two records with the same MGATH_SERV_GRP, MGATH_STAT, MGATH_TYP and start and end dates of the first disc are 01/JAN/2009 AND 01 / JAN / 2009.
start and end dates of second record are 15/JAN/2009 and 15/FEB/2009.
Here are the dates overlap. with my select query, I should get these two recordings.
I am using the following query. But it is too slow. Could you please suggest a better sql?
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Select MG_AUTH_AGNT m, MGATH_clnt, MGATH_beg_DT, MGATH_END_DT, MGATH_NHIC_ERR_CD, id where m.MGATH_SERV_GRP = '1' and m.MGATH_STAT = 'A' and MGATH_clnt = (select distinct MGATH_clnt of MG_AUTH_AGNT d where d.MGATH_SERV_GRP = m.MGATH_SERV_GRP and d.MGATH_TYP = m.MGATH_TYP and m.MGATH_CLNT = d.MGATH_CLNT and d.MGATH_STAT = m.MGATH_STAT and m.idd.id ((trunc (m.MGATH_beg_DT) & gt; = trunc (d.MGATH_beg_DT) and trunc (m.MGATH_beg_DT) & lt;=trunc(d.MGATH_END_DT)) or (trunc (m.MGATH_END_DT) & gt; = trunc (d.MGATH_beg_DT) and trunc (m.MGATH_END_DT) & lt; = trunc (d.MGATH_END_DT)) or (trunc (m.MGATH_beg_DT) & lt; = trunc (d.MGATH_beg_DT) and trunc (m.MGATH_END_DT) & gt; = trunc (d.MGATH_END_DT))) MGATH_clnt order MGATH_beg_DT
Published by: user10727414 on March 17, 2009 01:36user10727414 wrote:
My data is correctMGSRV_CLNT = MGSRV_BEG_DT = MGSRV_END_DT
501184242 = 28-AUG-07 = 31-DEC-9999
501184242 = 28-AUG-07 = 31-DEC-9999
501184242 = 20-DEC-07 = 31-DEC-9999
501184242 = 20-DEC-07 = 31-DEC-9999And we had to guess that a year of "99" was in fact "9999" were we? Hang on I'll go and dust off my crystal ball.
Well, now we know the correct dates (?), we'll put that in the original request...
SQL> ed Wrote file afiedt.buf 1 with mypeople as 2 (select 501184242 as id, to_date('28-AUG-2007','DD-MON-YYYY') as stdt, to_date('31-DEC-9999','DD-MON-YYYY') as endt from dual union all 3 select 501184242, to_date('28-AUG-2007','DD-MON-YYYY'), to_date('31-DEC-9999','DD-MON-YYYY') from dual union all 4 select 501184242, to_date('20-DEC-2007','DD-MON-YYYY'), to_date('31-DEC-9999','DD-MON-YYYY') from dual union all 5 select 501184242, to_date('20-DEC-2007','DD-MON-YYYY'), to_date('31-DEC-9999','DD-MON-YYYY') from dual union all 6 select 2, to_date('19/01/2009','DD/MM/YYYY'), to_date('24/01/2009','DD/MM/YYYY') from dual) 7 -- END OF TEST DATA 8 select id, stdt, endt 9 ,case when lead(stdt) over (partition by id order by stdt,endt) <= endt 10 or lag(endt) over (partition by id order by stdt,endt) >= stdt then 'Overlap' 11 else 'Ok' 12 end as status 13 from mypeople 14* order by id, stdt, endt SQL> / ID STDT ENDT STATUS ---------- --------- --------- ------- 2 19-JAN-09 24-JAN-09 Ok 501184242 28-AUG-07 31-DEC-99 Overlap 501184242 28-AUG-07 31-DEC-99 Overlap 501184242 20-DEC-07 31-DEC-99 Overlap 501184242 20-DEC-07 31-DEC-99 Overlap SQL>
Looks like it works for me.
If it does not work for you then maybe had better give us a statement of create table and insert to your data in the example statements then we can see what you're trying to do.
-
I HAV a real simple script that pulls information about DNS configuration & my ESXi hosts routing settings. version of ESXi 4.1 is
Get-VMHost | Get-VMHostNetwork | Select VMHost, VMKernelGateway, DnsAddress, DnsFromDhcp, hostname, domain name SearchDomain
When I use the above script I get the result on the screen I want to see:
$vmhost: MyHostDisplayName1
VMKernelGateway: 10.10.10.10
DnsAddress: {10.10.10.11, 10.10.10.12}
DnsFromDhcp: false
HostName: MyHostName1
Domain name: MyDomainName.local
SearchDomain: {MyDomainName.local}
When I try to channel this output in CSV format, I find myself with a problem:
Get-VMHost | Get-VMHostNetwork | Select VMHost, VMKernelGateway, DnsAddress, DnsFromDhcp, hostname, domain name SearchDomain | Export-Csv C:\VMHostDNSinfo.csv
My CSV does not show the SearchDomain or the DnsAddress. How to replace the [System.Stinr] with a correct output?
VMHost
VMKernelGateway
DnsAddress
DnsFromDhcp
Host name
Domain name
SearchDomain
MyHostDisplayName1
10.10.10.10
System.String]
FAKE
MyHostName1
MyDomainName.local
System.String]
MyHostDisplayName2
10.10.10.9
System.String]
FAKE
MyHostName2
MyDomainName.local
System.String]
MyHostDisplayName3
10.10.10.8
System.String]
FAKE
MyHostName3
MyDomainName.local
System.String]
You must convert arrays to strings before exporting them one. CSV file. You can do this with the following script:
Get-VMHost | Get-VMHostNetwork | ` Select-Object VMHost, VMKernelGateway, @{N="DnsAddress";E={[string]::Join(",",$_.DnsAddress)}}, DnsFromDhcp, HostName, DomainName, @{N="SearchDomain";E={[string]::Join(",",$_.SearchDomain)}} | ` Export-Csv -Path VMHostDNSinfo.csv -NoTypeInformation -UseCulture
Best regards, Robert
-
Export to CSV format without quotes
When I export to CSV, I want to do without surrounding quotes data...
I found other posts that confirmed this was not possible in SQL Developer 1.x, but I use the version 2.1.0.63 - anyone know if it is possible in this version?
Thank you
EmilyCurrently, there is no way to do this. However there was a feature presented in March 2008 request, asking this (among others); It is marked as "Accepted", but has only 3 votes. I suggest you add your vote to increase the chances it can get implemented at some point. The URL is http://htmldb.oracle.com/pls/otn/f?p=42626:39:1619641722802622:NO:P39_ID:10481.
HTH.
Hrsg.:.
-
Inventory of record Export in CSV format
Hello
I'm looking for a way to export the folders from the virtual computer inventory to a CSV file. Ideally, the list would include the path to the folder, the total number of VMS, vCPUs and RAM provisioned put in service. I would like the script to vCenter instead of by the datacenter or cluster.
Path of the folder. # VMs | # vCPUs | RAM (GB)
Cluster\Group1 1 1 1
Cluster\Group2 2 1 2
Any help is appreciated, thank you very much.
Try something like this, it descends recursively the blue folder structure.
Be sure to change the Datacentername!
Function Get-FolderPath {}
Param($FolderMoRef,$path='')
$Folder = get-view-Id $FolderMoRef
If ($Folder.Name - don't 'vm') {}
If ($Path - eq '-') {}
$currentPath = "$Path $($Folder.Name)".
}
else {}
$currentPath = ' $Path\ $($Folder.Name).
}
}
else {}
$currentPath = "\"
}
$vmIds = $Folder.ChildEntity | where {$_.} Type - eq 'VirtualMachine'}
{if ($vmIds)}
$vms = get-view-Id $vmIds
New-object PSObject-property @ {}
FolderPath = $currentPath
'#VM' = $vms. County
'#vCPU' = $vms | %{$_. Config.Hardware.NumCPU} | Measure-object-sum | Select - ExpandProperty sum
"GB vRAM" = [math]: Round (($vms | % {$_.)) Config.Hardware.MemoryMB} |
Measure-object-sum | (Select sum - ExpandProperty) / 1 Ko, 1).
}
}
else {}
New-object PSObject-property @ {}
FolderPath = $currentPath
'#VM' = 0
'#vCPU' = 0
"GB vRAM" = 0
}
}
$folderIds = $Folder.ChildEntity | where {$_.} Type - eq "File"}
{if ($folderIds)}
$folderIds | %{
Get-FolderPath-record $_-path $currentPath
}
}
# }
}
$dcName = "DC".
$root = get-data center-name $dcName | Get-file-name "vm".
Get-FolderPath - FolderMoRef $root. ExtensionData.Moref |
Select FolderPath, "#VM", "#vCPU", "GB vRAM |
Export Csv c:\vm-folder-report.csv - NoTypeInformation - UseCulture
-
Get-Annotation and export to CSV
I am trying to export of Annotation custom fields in a CSV with foreach and difficulty to operate there where I want.
1. is it possiible export with foreach or do I have to use foreach-object?
$vms = get-vm pt*
foreach ($vm in $vms){
$vm = Get-View $vm.ID
$nm = $vm.name
$hn = $vm.guest.hostname
$ip = $vm.guest.ipaddress
$contact = get-vm $vms | Get-Annotation -CustomAttribute "System Contact"|select Value
$vm | select `
@{Name = "Name"; E={$nm}},`
@{Name = "Contact"; E={$contact}},`
@{Name = "Hostname"; E={$hn}},`
@{Name = "IP"; E={$ip}}
}format-table -AutoSize -Wrap2. How can I get rid of the "{@{value ="in the exit?}} "
Name Contact Hostname IP
---- ------- -------- --
PT1 {@{Value=abcd.Serverteam... pt1.abcd.com 10.0.1.5
PT2 {@{Value=abcd.Serverteam... pt2.abcd.com 10.0.1.33The better, more PowerShell, way to do this would be to use the pipeline.
Something like that
Get-VM tp* | Select Name, @{N="Hostname";E={$_.Guest.Hostname}}, @{N="IP address";E={$_.Guest.IpAddress}}, @{N="Contact";E={ Get-Annotation -Entity $_ -CustomAttribute "System Contact" | Select -ExpandProperty Value}} | Export-Csv c:\report.csv -NoTypeInformation -UseCulture
-
How can I find the total size and free memory to a USB key?
Hello.
I am looking for procedures to obtain information of storage on a USB mass storage device. I use a Dell computer and windows XP Edition family. Thank you.
IT IS EVERYTHING!
I knew it was somewhere.
Thank you! Thank you! Thank you!
-
Outlook Express 6.00.2900.5512 (with XP Pro SP3) will not export to a. CSV file. The error message "Error exporting the address book" shows every time. I tried to export a new file name and also to a. CSV file saved with Excel.
Thanks for the suggestion, but it didn't work. Always to receive the same error message trying to export a new file or a .csv file that is saved on the desktop.
I am logged on as administrator so I hope this isn't a permission problem.
Just a thought and copied the file .wab Desktop on an old laptop. Ensuring that the export worked properly in the computer first, and he did. Then I renamed the files and tried to export the address book of office on the laptop, and it did not work. Which means there is probably something wrong with the office .wab.
Is that what you heard before?
-
Import-Csv c:\temp\esx.csv | {foreach}
SE connect-VIServer-Server $_. HV-user $user-Password $password
$rootFolder = get-file-name root-folder-ha
Get-VIPermission-Server $esx | where {$_.} Role - eq "Admin"} | Export-Csv - NoTypeInformation - UseCulture c:\xxx.csv > > > > >?
Disconnect-VIServer-confirm: $false
}
above is not... How to do things in exported xls?
Thank you
Something like that
$report = @)
Import-Csv c:\temp\esx.csv | {foreach}
SE connect-VIServer-Server $_. HV-user $user-Password $password
$rootFolder = get-file-name root-folder-ha
$report += get-VIPermission-Server $esx | where {$_.} Role - eq "Admin"} |
Select the entity, Principal, propagate, IsGroup
Disconnect-VIServer-confirm: $false
}
$report | Export-Csv - NoTypeInformation - UseCulture c:\xxx.csv
Maybe you are looking for
-
Mobile data connectivity problem
My phone shows that is has 4G in the status bar, but my application does not connect to the internet. But when I restart my device it becomes normal and same problem arises again. Can someone give me a permanent solution.
-
Have aw computer laptop Dell Inspiron 1501 XP SP3. Computer started to delay the result with a click of a button, etc. by seveal seconds. A ran the anti-virus, malware search, keylogers search and found nothing. The delay also occurs when you use a
-
Printer Spooler not started or has the error?
When you run in the installation or printing issues, and it gives you a message on your "Printer Spooler", it is usually in the service of your window. Here are some measures that you can get (again). 1. click on Start Menu2 right click computer3. ch
-
Hello I deleted by mistake a profile of switch, unfortunately it has been assigned to the switch connected to the outside world, so just now AIC is isolated. I don't have a backup configurations, what are the steps to retrieve the connection? Thank y
-
BlackBerry Bold 9900 Smartphones gone display
My Bold 9900 fell in the sink for 2 seconds and the display has now disappeared. Even the sound hearing is reduced now. Help, please. I can't find any service center in Aarhus, Denmark.