I am trying to write a script to get all of the information for my vm infrastructure. Using powercli and powershell I have all of my information and variables figured out thanks to this forum. I just figure out how to format and export them to csv in order to put into excel. These currently are my variables.
$VmInfo = Get-VM
$VMS = ($VmInfo).Name
$VMSysInfo = Get-VMGuest -VM $VmInfo
$Cluster_initial = &{foreach($vm in Get-VM){
Get-Datastore -RelatedObject $vm |
Select @{N='Cluster';E={Get-Cluster -VMHost $vm.VMhost | select -ExpandProperty Name}}}}
$cluster = $cluster_initial.cluster
$ESX_IHOST = ($VmInfo).VMHost.name
$VM_Name = ($VmInfo).name
$Power_Status = ($VmInfo).PowerState
$Memory_Allocated = ($VmInfo).MemoryGB
$CPU_Allocated = ($VmInfo).NumCpu
$StorageAllocated = ($VmInfo).ProvisionedSpaceGB
$DNS_Name = ($VmInfo).ExtensionData.Guest.Hostname
$Ip_Initial = Get-VM | Select Name, @{N="IP";E={@($_.guest.IPaddress[0])}}
$IP_Address = $Ip_Initial.IP
$vCenterServer = ($VmInfo).ExtensionData.Client.ServiceUrl.Split('/')[2].trimend(":443")
$cluster = $cluster_initial.cluster
Try like this.
If you are missing properties let me know.
@{N='Cluster';E={(Get-CLuster -VM $_).Name}},
@{N='ESXi';E={$_.VMHost.Name}},
PowerState,MemoryGB,NumCpu,ProvisionedSpaceGB,
@{N='DNSName';E={$_.ExtensionData.Guest.Hostname}},
@{N='IP';E={$_.Guest.IPaddress[0]}},
@{N='vCenter';E={$_.ExtensionData.Client.ServiceUrl.Split('/')[2].trimend(":443")}} |
Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this.
If you are missing properties let me know.
@{N='Cluster';E={(Get-CLuster -VM $_).Name}},
@{N='ESXi';E={$_.VMHost.Name}},
PowerState,MemoryGB,NumCpu,ProvisionedSpaceGB,
@{N='DNSName';E={$_.ExtensionData.Guest.Hostname}},
@{N='IP';E={$_.Guest.IPaddress[0]}},
@{N='vCenter';E={$_.ExtensionData.Client.ServiceUrl.Split('/')[2].trimend(":443")}} |
Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Forgot the commas and the pipe. Thanks for the help. Was exactly what I was looking for.