Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 219035

Re: get useful vm information with guest OS

$
0
0

Hi LucD,

 

I am using following script

 

filter Get-FolderPath {
$vm | % {
$fol = "" | select Name, Path
$fol.Name = $vm.Name

$current = Get-View $vm.Parent
#        $path = $_.Name # Uncomment out this line if you do want the VM Name to appear at the end of the path
$path = ""
do {
$parent = $current
if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path}
$current = Get-View $current.Parent
} while ($current.Parent -ne $null)
$fol.Path = $path
$fol
}
}

 

$report = @()
$vms = Get-View -ViewType "virtualmachine"
foreach($vm in $vms){
foreach($dev in $vm.Config.Hardware.Device){
if(($dev.gettype()).Name -eq "VirtualDisk"){
$data = "" | select VMName, FolderName, PowerState, HostName, ClusterName, OSVersion, OSEdition, GuestIPAddress, ToolsStatus, NumCPU, MemoryMB, DeviceInfo, CapacityInGB, Datastore
$data.VMName = $vm.Name
$OSV = Get-WmiObject -computername $vm.Name -class Win32_OperatingSystem

#$data.FolderName = (get-view -id $vm.parent).name
$data.FolderName = ($vm | Get-Folderpath).Path
$data.PowerState = $vm.runtime.powerstate
$data.HostName = (get-view -id $vm.runtime.host).name
$clu = (get-view -id $vm.Runtime.Host).parent
$data.ClusterName = (Get-View -id $clu).name
$data.OSVersion = $vm.summary.guest.guestfullname
$data.OSEdition = $OSV.Caption
$data.GuestIPAddress = $vm.guest.ipaddress
$data.ToolsStatus = $vm.guest.toolsstatus
$data.NumCPU = $vm.config.hardware.numcpu
$data.MemoryMB = $vm.config.hardware.MemoryMB
$data.DeviceInfo = $dev.deviceinfo.label
$data.CapacityInGB = [system.math]::Round($dev.CapacityInKB / 1048576)
$data.Datastore = $dev.backing.filename.split("]")[0].trim("[")
$report += $data
}
}
}
#$report | Export-Csv C:\VMReport\csvfiles\NAPVMReport.csv -NoTypeInformation -UseCulture
$report = $report | Sort-Object FolderName
IF ($Report -ne "") {
$report | Export-Csv C:\VMReport.csv -NoTypeInformation -UseCulture
}

 

I've added the WMIObject class, but I am getting following error. and I would like draw your attention that we are having multiple domain and forest environment

 

--------------------------------------------

Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:28 char:24
+    $OSV = Get-WmiObject <<<<  -computername $vm.Name -class Win32_OperatingSystem
+ CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

 

----------------------------------------------

 

Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At line:28 char:24
+    $OSV = Get-WmiObject <<<<  -computername $vm.Name -class Win32_OperatingSystem
+ CategoryInfo          : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

 

 

 

Waiting for you reply,

 

Thanks,

Samir


Viewing all articles
Browse latest Browse all 219035

Trending Articles