Script 1 succesfully passed..
Add-PSSnapin VMware.VimAutomation.Core
Remove-Item "C:\report.csv"
$vCenterServerName = "vc1","vc2"
foreach($vcenter in $vCenterServerName){
connect-viserver -server $vcenter
$objects = @()
foreach($cluster in (Get-Cluster -Server $vcenter) ){
foreach($esx in (Get-VMHost -Location $cluster -Server $vcenter)){
foreach($vm in (Get-VM -Location $esx -Server $vcenter)){
foreach($hd in (Get-HardDisk -VM $vm -Server $vcenter)){
$obj = "" | select vCenter , Cluster , VMHost , VMHostRamGB , VMHostCpu , VM , VMRamGB , VmCpu , Disk , DiskGB
$obj.vCenter = $vcenter
$obj.Cluster = $cluster.name
$obj.VMHost = $esx.Name
$obj.VMHostRamGB= $esx.MemoryTotalGB
$obj.VMHostCpu = $esx.NumCpu
$obj.VM = $vm.Name
$obj.VMRamGB = $vm.MemoryGB
$obj.VmCpu = $vm.NumCpu
$obj.Disk = $hd.Name
$obj.DiskGB = $hd.CapacityGB
$objects += $obj
}
}
}
}$objects | Export-Csv -Append -Path "C:\report.csv"
disconnect-viserver -server $vcenter -Confirm:$false
}
script 2 continuously getting failed
The script didn't throws any error
The script able to connect to Vc
and provides 0b file
Add-PSSnapin VMware.VimAutomation.Core
Remove-Item "C:\Datastorereport.csv"
$vCenterServerName = "vc1" , "vc2"
foreach($vcenter in $vCenterServerName){
connect-viserver -server $vcenter
$objects = @()
foreach ( $dsc in Get-DatastoreCluster -server $vcenter){
foreach($ds in Get-Datastore -Location $dsc -server $vcenter){
foreach($vm in Get-VM -Datastore $ds -server $vcenter){
foreach($hd in Get-HardDisk -VM $vm -server $vcenter){
$obj = "" | select vCenter , DatastoreCluster , Datastore, CapacityGB , VMRamGB , VmCpu , UsedGB , VM , Disk , DiskGB
$obj.vCenter = $vcenter
$obj.DatastoreCluster = $dsc.name
$obj.Datastore = $ds.Name
$obj.CapacityGB = $ds.CapacityGB
$obj.UsedGB = $ds.CapacityGB - $ds.FreeSpaceGB
$obj.VM = $vm.Name
$obj.VMRamGB = $vm.MemoryGB
$obj.VmCpu = $vm.NumCpu
$obj.Disk = $hd.Name
$obj.DiskGB = $hd.CapacityGB
$objects += $obj
}
}
}
}$objects | Export-Csv -Append -Path "C:\Datastorereport.csv"
disconnect-viserver -server $vcenter -Confirm:$false
}
Please let me know do i need to change anything
i guess the issues is with $dsc and $ds
Please help me to resolve the issue