Hello VMGurus,
I am using following link to get vm information and it's working
http://communities.vmware.com/message/2100780#2100780
the only problem is I am not getting the guest OS edition and version, using this script I am getting OS which I've selected during the creation of VM.
is there any way that we can incorporate wmi caption in this script and get exact OS edition and version like in wmi caption?
thanks in advance for your help.
Regards,
Samir.
With
Get-WmiObject Win32_OperatingSystem -Computer $vm.Name
you can get the class with the OS info.
Which properties do you want to include ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hi LucD,
thanks for your prompt reply, I want to include Operating system caption, sp and architecture
I've tried following
$VMInfo.OS = (Get-WmiObject -computername $vm -class Win32_OperatingSystem).Caption but it's not working.
I don't know how to use this, if you can help I would be very thank ful to you.
Thanks,
Samir
The architecture is in another WMI class.
Try adding something like this
$os = Get-WmiObject -computername $vm.Name -class Win32_OperatingSystem
$proc = Get-WmiObject -computername $vm.Name -class Win32_Processor
$VMInfo.OS = $os.Caption
$VMInfo.SP = $os.CSDVersion
$VMInfo.Architecture = $proc.AddressWidth
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
It looks like the guest OS is not configured to allow remote WMI calls, they need the RPC service to be running and to be configured correctly.
An alternative, provided you have the required OS version, is to use the Invoke-VMScript cmdlet and run the Get-WmiObject inside the guest OS.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference