Thank you, when I run that script alone it works fine.
How can I incorporate that in to mine though? Do I need to do something instead of get-vm?
This is what I just tried, and the vcpu and vcpu cores came back blank
function Get-VMinventory {
function Get-RDMDisk {
[CmdletBinding()]
param (
[Parameter(Mandatory=$True)]
[string[]]$VMName
)
$RDMInfo = Get-VM -Name $VMName | Get-HardDisk -DiskType RawPhysical, RawVirtual
$Result = foreach ($RDM in $RDMInfo) {
"{0}/{1}/{2}/{3}"-f ($RDM.Name), ($RDM.DiskType),($RDM.Filename), ($RDM.ScsiCanonicalName)
}
$Result -join (", ")
}
function Get-vNicInfo {
[CmdletBinding()]
param (
[Parameter(Mandatory=$True)]
[string[]]$VMName
)
$vNicInfo = Get-VM -Name $VMName | Get-NetworkAdapter
$Result = foreach ($vNic in $VnicInfo) {
"{0}={1}"-f ($vnic.Name.split("")[2]), ($vNic.Type)
}
$Result -join (", ")
}
function Get-InternalHDD {
[CmdletBinding()]
param (
[Parameter(Mandatory=$True)]
[string[]]$VMName
)
$VMInfo = Get-VMGuest -VM $VMName # (get-vm $VMName).extensiondata
$InternalHDD = $VMInfo.ExtensionData.disk
$result = foreach ($vdisk in $InternalHDD) {
"{0}={1}GB/{2}GB"-f ($vdisk.DiskPath), ($vdisk.FreeSpace /1GB -as [int]),($vdisk.Capacity /1GB -as [int])
}
$result -join (", ")
}
foreach ($vm in (get-view -viewtype VirtualMachine)) {
$properties = @{'VMName'=$vm.Name;
'IP Address'= $vm.Guest.IPAddress[0]; #$VM.ExtensionData.Summary.Guest.IpAddress
'vCPU'= $vm.config.hardware.NumCPU;
'vCPU Cores'= $vm.config.hardware.NumCoresPerSocket;
'RAM(GB)'= $vm.MemoryGB;
'Total-HDD(GB)'= $vm.ProvisionedSpaceGB -as [int];
'HDDs(GB)'= ($vm | get-harddisk | select-object -ExpandProperty CapacityGB) -join " + "
'Datastore'= (Get-Datastore -vm $vm) -split ", " -join ", ";
'Partition/Size' = Get-InternalHDD -VMName $vm.Name
'Operating System'= $vm.guest.OSFullName;
'Hardware Version'= $vm.Version;
'VMX' = $vm.ExtensionData.config.files.VMpathname;
'VMDK' = ($vm | Get-HardDisk).filename -join ", ";
'VMTools Status' = $vm.ExtensionData.Guest.ToolsStatus;
'VMTools Ver' = $vm.ExtensionData.Guest.ToolsVersion;
'SnapShots' = ($vm | get-snapshot).count;
'DataCenter' = $vm | Get-Datacenter;
'vNic' = Get-VNICinfo -VMName $vm.name;
'PortGroup' = ($vm | Get-NetworkAdapter).NetworkName -join ", ";
'RDMs' = Get-RDMDisk -VMName $VM.name
}
$obj = New-Object -TypeName PSObject -Property $properties
Write-Output $obj | select-object -Property 'VMName', 'IP Address', 'Operating System', 'vCPU', 'vCPU Cores', 'RAM(GB)', 'Total-HDD(GB)' ,'HDDs(GB)', 'Datastore', 'Partition/Size', 'Hardware Version', 'VMX', 'VMDK', 'VMTools Status', 'VMTools Ver', 'SnapShots', 'DataCenter', 'vNic', 'PortGroup', 'RDMs'
}
}
Get-VMinventory | Export-Csv "C:\ppi\VM-report.csv" -NoTypeInformation -UseCulture