Hi
Please find below my script. I am not able to export the output to csv/xls file. Please help me. And also i have 10 vcenters, I need this report in xls format with each VC worksheets in one excel file.
$VM = Get-Cluster test-cluster | Get-VM | `
ForEach-Object {
$VM = $_
$VMview = $VM | Get-View
$Snapshots = $VM | Get-Snapshot
$Report = “” | Select-Object VMname,vmCreatedByUser,vmCreatedDate,ESXname,ClusterName,MemoryGB,vCPUcount,VMXname,VmdkSizeGB,DatastoreName,SnapshotCount,Owner
$Report.VMName = $VM.name
$Report.vmCreatedByUser = Get-VIEvent $VM | sort createdTime | select -first 1 | select UserName | % {$.UserName.split(“")[1]}
$Report.vmCreatedDate = Get-VIEvent $VM | sort createdTime | select -first 1 | select CreatedTime
$Report.ESXname = $VM.VMHost
$Report.ClusterName = ($VM | Get-Cluster).Name
$Report.MemoryGB = $VM.MemoryMB/1024
$Report.vCPUcount = $VM.NumCpu
$Report.VMXname = $VM.ExtensionData.Config.Files.VmPathName.Split(”/")[1]
$Report.VmdkSizeGB = $VM.UsedSpaceGB
$Report.DatastoreName = $VMview.Config.DatastoreUrl
$Report.SnapshotCount = ($VM | Get-Snapshot).Count
$Report.Owner = $VM | Get-VIPermission | Where-Object {$.Role -like “xxxxxx*”} | select Principal | % {$_.Principal.split("")[1]}
Write-Output $Report
}
Thanks
Raghav