My envirornment consists of 100 + hosts. half of hosts are in vCenter rest are alone.
Now, every now and then I need to fetch information about those Esxi host not in vCenter.
Note :- All the hosts are running on 5 + versions.
Is there any powerCli script to fetch information. for eg. I need to know the ESXi version. Build, of all ESXi host in my environment.
Plesae let me know if anyone has any such script.
You can still use "Connect-VIServer" when connecting directly to an ESXi host, eg:
Connect-VIServer -Server ESXi01 -User root -Password password123
I normally use one of these when connected to vCenter, but they may also work connected directly to a host, worth a try:
Get-View -ViewType HostSystem -Property Name, Config.Product | select Name,{$_.Config.Product.FullName},{$_.Config.Product.Build} | ft -auto
or...
Get-VMHost | Select Name,Version | ft -auto
or...
Get-VMHost | Select Name,@{N='Product';E={$_.ExtensionData.Config.Product.Name}},Version,Build
you can try below
Connect-VIServer hostname "FQDN/ip of your esxi host" -User root -Password "your root password"
Get-VM | select name, numcpu, memorymb, vmhost, powerstate | export-csv c:\users\username\desktop\report.csv -notypeinformation
above will give you list of all vm's on that esxi host with cpu numbers, memory in MB, name of the host, powerstate of the vm's and last the report will be exported to the specified location
I have used those commands for fetching the details one by one. But this cannot be used for get the details from 70 ESXi host in one go.
I need a Script, which pulls out list of ESXi from any .txt and pulls out information one by one, by logging in.
I have used those commands for fetching the details one by one. But this cannot be used for get the details from 70 ESXi host in one go.
I need a Script, which pulls out list of ESXi from any .txt and pulls out information one by one, by logging in.
ok ,lets try this:
connect-viserver -server "FQDN/ip of your host" -user root -password "your root password"
$hostlist = Get-Content c:\users\username\desktop\hostlist.csv
foreach ($var in $hostlist) {Get-VMHost | Select-Object -Property Name, version}
where hostlist is the name of the file where there is a list of esxi hosts, for a loop of all esxi ,copy this script in a notepad and change the host name to connect to in every line, this script can be saved and run as scheduled task
let me know if this works for you
connect-viserver -server "FQDN/ip of your host" -user root -password "your root password" //which ESXi will it connect ? first it should pick an ESXi from list. then should try to connect them one by one. So this will not work..
$hostlist = Get-Content c:\users\username\desktop\hostlist.csv
foreach ($var in $hostlist) {Get-VMHost | Select-Object -Property Name, version} // please if possible, try to produce the output in a Text file.
try this:
$esxicreds = Get-Credential
foreach ($var in $hostlist) { Get-VMHost | Select-Object -Property Name, version, build | export-csv c:\users\username\desktop\test.csv -notypeinformation }
**********************************************************************************@@@
$esxicreds = Get-Credential
$hostlist = import-csv c:\users\username\desktop\hostlist.csv
foreach ($hostname in $hostlist)
connect-viserver $hostname -credentials $esxicreds
foreach ($var in $hostlist) {Get-VMHost | Select-Object -Property Name, version, build | export-csv c:\users\username\desktop\test.csv -notypeinformation }
**********************************************************************************
$esxicreds = Get-Credential
$esxitargets = import-csv c:\users\username\desktop\hostlist.csv
foreach ($hostname in $esxitargets) {
connect-viserver $hostname -credential $esxicreds
foreach ($var in $hostlist) { Get-VMHost | Select-Object -Property Name, version, build | export-csv c:\users\username\desktop\test.csv -notypeinformation }
**********************************************************************************
$esxicreds = Get-Credential
$esxitargets = "FQDN/ip of host name" , "FQDN/ip of host name" , "FQDN/ip of host name"
foreach ($hostname in $esxitargets) {
connect-viserver $hostname -credential $esxicreds
$esxihost = get-VMHost $hostname
}
LucD looping the master here , m sure he can help us here, luc pls see if any of the above will work
You could look at the vpxa service and if it is running.
# Assumes you can use the same credentials for each ESXi host
$cred = Get-Credential
$report = @()
Get-Content -Path hosts.txt | %{
if(Test-Connection -ComputerName $_ -Quiet -Count 1){
Connect-VIServer -Server $_ -Credential $cred > $null
$online = $true
$esx = Get-VMHost -Name $_
if($esx.ExtensionData.Config.Service.Service | where{$_.Key -eq 'vpxa' -and $_.Running}){
$vCenter = $esx.Uid.split('@')[1].Split(':')[0]
}
else{
$vCenter = '<standalone>'
}
}
else{
$online = $false
$vCenter = 'na'
}
$report += New-Object PSObject -Property @{
Hostname = $_
Online = $online
vCenter = $vCenter
}
}
$report | Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD,
That is working but I needed different set of details.
I did some modification but it didn't fetched desired results. I need to pull out information eg. (ESXi version/build.)
(IMP:- Yes, all the ESXi has same password. )
$cred = Get-Credential
$report = @()
Get-Content -Path hosts.txt | %{ \\ i used it like Get-Content D:\hosts1.txt | %{
if(Test-Connection -ComputerName $_ -Quiet -Count 1){
Connect-VIServer -Server $_ -Credential $cred > $null
$online = $true
$esx = Get-VMHost -Name $_
if($esx.ExtensionData.Config.Service.Service | where{$_.Key -eq 'vpxa' -and $_.Running}){
$vCenter = $esx.Uid.split('@')[1].Split(':')[0]
}
else{
$vCenter = '<standalone>'
\\ I used this :- $Version = Get-VMHost | Select-Object -Property version
}
}
else{
$online = $false
$vCenter = 'na'
}
$report += New-Object PSObject -Property @{
Hostname = $_
Online = $online
vCenter = $vCenter \\ here I tried adding additional line :- Version = $Version
}
}
$report | Export-Csv report.csv -NoTypeInformation -UseCulture
Results :-
the First column is showing Version as some error ie., System.Object[]. Rest of 3 columns are fine
Hi LucD,
Did you get a chance to look into my previous reply. I pointed out few things in your script.
Hello Mr. Rathore,
I used the below one :--
$esxicreds = Get-Credential
$esxitargets = import-csv E:\Mukesh\hosts1.csv
foreach ($hostname in $esxitargets) {
connect-viserver $hostname -credential $esxicreds
foreach ($var in $hostlist) { Get-VMHost | Select-Object -Property Name, version, build | export-csv E:\Mukesh\test.csv -notypeinformation }
It was working earlier and I fetched data as well : though with some errors on screen, but was working.
But today again, found that its not working... getting the below error on screen. .CSV file is getting created.
Error below :-
Get-VMHost : 8/16/2016 12:22:10 PM | Get-VMHost | You are not currently c |
onnected to any servers. Please connect first using a Connect cmdlet.
At E:\Mukesh\Scripts.ps1:5 char:41
+ foreach ($var in $hostlist) { Get-VMHost <<<< | Select-Object -Property Name
, version, build | export-csv E:\Mukesh\test.csv -notypeinformation }
+ CategoryInfo | : ResourceUnavailable: (:) [Get-VMHost], ViServerC |
onnectionException
+ FullyQualifiedErrorId : Core_BaseCmdlet_NotConnectedError,VMware.VimAuto |
mation.ViCore.Cmdlets.Commands.GetVMHost
Hii LucD,
Plz check my resposes in this thread. The one provided by need some modifications to get desired output. Arathore tried a few things, which is not working.
Hello LucD/Chs1,
I am eagerly waiting for your response, From the script below, I needed to extract the information ( eg, esxi's version and build )
I have tried many things, finally exhausted.
Looping another master chs1
If i try to add that it pulls out powercli version and build. How to get the ESXi version and build from below script?