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

Cant get a VMs Powerstate

$
0
0

I'm trying to create a single file of several thousand VMs in all vSpheres. I'm collecting cluster, ESX host and vm details. In the code below, powerstate1 is alwasy blank and powerstate2 always ="poweredOff"

 

Any ideas?

 

Thanks!

 

$Reports

= @()

$viservers

="x1-svr-tb","x2-svr-g6","x3-svr-vc","x4-svr-a3","x5-svr-vc","x6-svr-vc","x7-svr-vc","x8-svr-vc"

foreach

($singleViserverin$viservers)

{ Connect-VIServer

$singleViserver–credential $mycred

 

Get-Date-uformat"Connected to VIServer $singleViserver %Y/%m/%d-%H:%M:%S"

 

# On the next like, you must select the columns you want out of Get-VMHost or else it will just pull the name.

 

$vmhosts= Get-VMHost | Select Name, State, Build, Manufacturer, Model, ProcessorType,parent,

@{N

="ClusterName";E={($_ | Get-Cluster).Name}},

@{N

="NumCPU";E={($_| Get-View).Hardware.CpuInfo.NumCpuPackages}},

@{N

="Cores";E={($_| Get-View).Hardware.CpuInfo.NumCpuCores}}

 

ForEach ($VMHostin$vmhosts)

{

 

$ESXHost=$VMHost.Name

 

$Cluster=$VMHost.ClusterName

 

 

Get-Date-uformat" Cluster=$Cluster, ESXHost=$ESXHost %Y/%m/%d-%H:%M:%S"

 

foreach ($VMin (Get-View -ViewType "VirtualMachine" -Property Name,guest.guestfullname,Runtime.Host,Config.Hardware `

-Filter @{

"Runtime.PowerState"="PoweredOn"} `

-SearchRoot $(Get-View -ViewType

"HostSystem" -Filter @{"Name"=$ESXHost} -Property Name ).MoRef))

{

 

$VMInfo="" | Select-Object VIServer, ESX_HostName, ESX_Hoststate , ESX_NumCPU, ESX_Cores, Cluster_Name,VM_name, VM_OS, VM_memory, VM_CPU, vm_powerstate1, vm_powerstate2

 

$VMInfo.VIServer =$singleViserver

 

$VMInfo.ESX_HostName =$VMHost.name

 

$VMInfo.ESX_Hoststate =$VMHost.state

 

$VMInfo.ESX_NumCPU =$VMHost.NumCPU

 

$VMInfo.ESX_Cores =$VMHost.Cores

 

$VMInfo.Cluster_Name =$VMHost.ClusterName

 

$VMInfo.VM_name =$VM.name

 

$VMInfo.VM_OS=$VM.guest.guestfullname

 

$VMInfo.VM_Memory =$VM.Config.Hardware.memoryMB

 

$VMInfo.VM_Cpu =$VM.Config.Hardware.numCPU

$VMHostInfo.VM_Powerstate1 =$VM.powerstate

 

$VMHostInfo.VM_Powerstate2 =$VM.runtime.powerstate

#Get-Date -uformat "Cluster=$Cluster, ESXHost=$ESXHost %Y/%m/%d-%H:%M:%S"

 

$Reports+=$VMInfo

}

}

}

IF

($Reports-ne"") {

$Reports

| Export-Csv–path"C:\Downloads\Powercli\VMHost-info2.csv"-NoTypeInformation

}

 

#Get-Date -uformat "Cluster=$Cluster, ESXHost=$ESXHost %Y/%m/%d-%H:%M:%S"

 

$Reports+=$VMInfo

}

}

}

IF

($Reports-ne"") {

$Reports

| Export-Csv–path"C:\Downloads\Powercli\VMHost-info2.csv"-NoTypeInformation

}

#Get-Date -uformat "Cluster=$Cluster, ESXHost=$ESXHost %Y/%m/%d-%H:%M:%S"

 

$Reports+=$VMInfo

}

}

}

IF

($Reports-ne"") {

$Reports

| Export-Csv–path"C:\Downloads\Powercli\VMHost-info2.csv"-NoTypeInformation

}

 

 

 


Viewing all articles
Browse latest Browse all 232869

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>