esxi详细信息

esxi detailed Information

我想从 ESXi 获取所有信息。我在不同的CSV文件中提取了信息,但是一旦我想合并它们,它并没有显示全部。但我宁愿创建 foreach 来收集相同的信息。

Add-PsSnapin VMware.VimAutomation.Core -ErrorAction  "SilentlyContinue"
Import-Module ‚C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1‘

$datetime = Get-Date -Format "ddMMyyyy";

# Configuration Block
$User =  
$Password =  
$ESXiServer = "172.17.1.171"

# Connect to ESXi
$PWD = ConvertTo-SecureString -AsPlainText -Force -String $Password;
$SourceCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$PWD; 
$sourceConnection = New-MvmcSourceConnection -Server $ESXiServer -SourceCredential $sourceCredential

$SourceVMName = (Get-MvmcSourceVirtualMachine -SourceConnection $sourceconnection).Name
$Datacenter = Get-Datacenter
$Datastore = Get-Datastore
$DataStoreLocation = $Datastore.ExtensionData.info.url  
$Datastore = Get-Datastore

# Get-VMHostNetworkAdapter | fl *
Get-VMHostNetworkAdapter | select VMhost, Name, IP, SubnetMask, Mac, DHCPEnabled, DeviceName  | Export-Csv C:\VMHostNetworkDetails_$datetime.csv -Delimiter ";"
Get-MvmcSourceVirtualMachine -SourceConnection $sourceconnection | select MemorySizeBytes, OperatingSystem, UsedSpacebytes | Export-Csv C:\VMRAmDetails_$datetime.csv -Delimiter ";"
$Global:DefaultVIServers | Select ProductLine,Version,Build, Port | Export-Csv C:\GlobalDetails_$datetime.csv -Delimiter ";"
@(Import-Csv C:\VMHostNetworkDetails_$datetime.csv) + @(Import-Csv C:\VMRAmDetails_$datetime.csv) + @(Import-Csv C:\GlobalDetails_$datetime.csv) | Export-Csv C:\ESxiDetails_$datetime.csv -Delimiter ";"

注意:get-vm 对我不起作用。

编辑:
我尝试使用 foreach 循环获取信息,但无法获取 IP、SubnetMask、Mac、DHCPEnabled。$VMSysInfo.IPAddress 没有给我任何 IP,但 Get-VMHostNetworkAdapter | select VMhost, Name, IP, SubnetMask, Mac, DHCPEnabled, DeviceName 给我 IP。

$VmInfo = vmware.vimautomation.core\Get-VM
$VMS = ($VmInfo).Name
$VCenter = @()
foreach ($VM in $VMS)
{
    $HostServer = (($VmInfo | ? {$_.Name -eq $VM}).Host).Name
    $VMSysInfo = Get-VMGuest -VM $VM
    $MyObject = New-Object PSObject -Property @{
    VMName = $VM
    #VMHostName = $VMSysInfo.HostName
    VMIP = $VMSysInfo.IPAddress
    VMInstalledOS = $VMSysInfo.OSFullName
    PowerState = ($VmInfo | ? {$_.Name -eq $VM}).PowerState
    NumberOfCPU = ($VmInfo | ? {$_.Name -eq $VM}).NumCpu
    MemoryGB = (($VmInfo | ? {$_.Name -eq $VM}).MemoryMB/1024)
    VMDataS = (Get-Datastore -VM $VM).Name
    #HostServer = (($VmInfo | ? {$_.Name -eq $VM}).Host).Name
    #HostCluster = (Get-Cluster -VMHost $HostServer).Name
    Datacenter = (Get-Datacenter -VM $vm).Name
    #Notes =   $vm | Select -ExpandProperty Description
    Portgroup = (Get-VirtualPortGroup -VM $vm).Name
    }
     $VCenter += $MyObject
        }
    $VCenter | Select VMName,
    @{N='VMIPAddress';E={$_.VMIP -join '; '}},
    VMInstalledOS, PowerState, NumberOfCPU, MemoryGB,
    @{N='VMDataStore';E={$_.VMDataS -join '; '}},
    HostServer, HostCluster,Datacenter, Notes, Portgroup |
    Export-Csv C:\test.csv -NoTypeInformation -Delimiter ";"

我更改了 foreach 循环并且它起作用了:

$VmInfo = vmware.vimautomation.core\Get-VM
#$VmInfo = (Get-MvmcSourceVirtualMachine -SourceConnection $sourceconnection).Name
$VMS = ($VmInfo).Name
$Data = @()
foreach ($VM in $VMS)
{
    $Datacenter = Get-Datacenter
    $Datastore = Get-Datastore
    $SourceIP =  ($global:DefaultVIServer).name
    $DataStoreLocation = $Datastore.ExtensionData.info.url  

    $VMNetwork = Get-VMHostNetworkAdapter
    $PortalGroup = Get-VirtualPortGroup -VM $vm
    $MvmcSourceVirtualMachine = Get-MvmcSourceVirtualMachine -SourceConnection $sourceconnection

    $VMCustom = New-Object System.Object

    $VMCustom | Add-Member -Type NoteProperty -Name DataCenter -Value $Datacenter.Name
    $VMCustom | Add-Member -Type NoteProperty -Name DataStoreName -Value $Datastore.Name
    $VMCustom | Add-Member -Type NoteProperty -Name DataStoreLocation -Value $DataStoreLocation
    $VMCustom | Add-Member -Type NoteProperty -Name NumberOfCPU -Value $VmInfo.NumCpu
    $VMCustom | Add-Member -Type NoteProperty -Name PowerState -Value $VmInfo.PowerState
    $VMCustom | Add-Member -Type NoteProperty -Name MemoryGB -Value $VmInfo.MemoryGB
    $VMCustom | Add-Member -Type NoteProperty -Name VMHost -Value $VMNetwork.VMhost
    $VMCustom | Add-Member -Type NoteProperty -Name DHCP -Value $VMNetwork.DHCPEnabled
    $VMCustom | Add-Member -Type NoteProperty -Name SubnetMask -Value $VMNetwork.SubnetMask
    $VMCustom | Add-Member -Type NoteProperty -Name Client -Value $VMNetwork.Client
    $VMCustom | Add-Member -Type NoteProperty -Name IP -Value $SourceIP
    $VMCustom | Add-Member -Type NoteProperty -Name MacAddress -Value $VMNetwork.Mac
    $VMCustom | Add-Member -Type NoteProperty -Name PortalGroupName -Value $PortalGroup.Name
    $VMCustom | Add-Member -Type NoteProperty -Name OperatingSystem -Value $MvmcSourceVirtualMachine.OperatingSystem

    $Data += $VMCustom
}

$Data   | Export-CSV "C:\ESXiInfo.csv" -Delimiter ";" -NoTypeInformation