$locations= @{"S1"="Site1";"S2"="Site2"; "S3"="Site3"; "S4"="Site4"; "S5"="Site5"}
$vcenters= @("vcenter01","vcenter02")
$rpt= @()
Foreach
($vc in $vcenters) {
Connect-VIServer -Server $vc #| Out-Null
foreach ($site in (Get-Folder datacenters | Get-Folder -NoRecursion | Sort-Object $_.name)) {
Foreach ($VM in ($site | Get-VM | Where-Object {$_.powerstate -eq "PoweredOn"} | Sort-Object $_.name)){
$tmp = "" | select Asset_Name, Model, Serial_Number, Asset_Tag, Description, Manufacturer, Asset_Type, Class, location, In_DMZ, Portfolio_Status, Primary_Contact_empid, Primary_Contact_LANID, Primary_Support_Contact_LANID, Record_Status_Inactive, Usage_Status, Deployment_Status, Service_Status, Received_Date, Warranty_Type, Warranty_Start_Date, Warranty_End_Date, Server_Type, Floor_Location, Room_Location, Cabinet_Location, Shelf_Location, Slot_Location, Operating_System, Product_Version, Maintenance_Org_Code, Service_Type;
Write-Host $site.name $locations.get_item($site.name) $VM.Name
$tmp.Asset_Name = $VM.Name
$tmp.Serial_Number = $VM.Name
$tmp.Asset_Type = "Hardware.Server"
$tmp.Model = "Virtual"
$tmp.Class = "Virtual"
$tmp.Portfolio_Status = "Active"
$tmp.Operating_System = (get-view $vm.id).guest.guestfullname
$tmp.location = $locations.get_item($site.name)
$tmp.Maintenance_Org_Code = "CCG872"
$rpt += $tmp
}
}
Disconnect-VIServer -Confirm:$false -server $vc
}