1 Rookie
•
7 Posts
0
520
September 5th, 2023 17:50
How to get host nqn info via powershell
Hi,
I have a very large environment with hundreds of dell rack servers connected to seperate vcenters. To get host nqn info I have a string to run in ssh by connecting each host via ssh seperately. But all these hosts are connected to vmware vcenter, and I do run most of the ssh commands converted to powercli.
For below command, is there a way to convert it to powercli or powershell to get nqn info for a cluster or all hosts connected to same vcenter?
esxcli nvme info get
No Events found!
VmwareGeek
1 Rookie
•
7 Posts
0
September 5th, 2023 21:19
Before I get a response, I developed below command set for exactly what I need. I am sharing it.
Below command requests user to enter name of cluster, then after write and hit ENTER gets the NQN info and lists it.
Connect-VIServer vcenter.fqdn
$clusterName=Read-Host "Enter a cluster name to continue"
$cluster=Get-Cluster -Name $clusterName
$HostList=Get-Cluster $cluster | Get-VMHost
foreach($esxi in $hostList) { $esxcli=Get-EsxCli -VMHost $esxi -V2
$esxcli.nvme.info.get.invoke()
$esxcli }
Example result;
Gatto Sama
1 Rookie
•
93 Posts
0
September 6th, 2023 15:15
To retrieve the NVMe Qualified Name (NQN) information for ESXi hosts in a cluster or all hosts connected to the same vCenter using PowerCLI, you can use the following PowerShell script. This script prompts you to enter the name of the cluster, then it fetches the NQN information for each host in that cluster:
# Connect to the vCenter server
Connect-VIServer -Server <vCenterServer>
# Prompt for the cluster name
$clusterName = Read-Host "Enter the cluster name"
# Get the cluster object
$cluster = Get-Cluster -Name $clusterName
# Get all ESXi hosts in the cluster
$hosts = Get-Cluster $cluster | Get-VMHost
# Iterate through each ESXi host and retrieve NQN info
foreach ($host in $hosts) {
$esxcli = Get-EsxCli -VMHost
$host $nqnInfo = $esxcli.nvme.info.get.invoke()
Write-Host "ESXi Host: $($host.Name)"
Write-Host "NQN Info: $($nqnInfo.Output)" -ForegroundColor Green
Write-Host ""
}
# Disconnect from the vCenter server Disconnect-VIServer -Confirm:$false
Here's how the script works:
It connects to the vCenter server using
Connect-VIServer
.It prompts you to enter the name of the cluster.
It retrieves the cluster object based on the provided cluster name.
It gets a list of all ESXi hosts in the cluster.
It iterates through each ESXi host, retrieves the NQN info using the
esxcli.nvme.info.get.invoke()
method, and displays the information.Finally, it disconnects from the vCenter server using
Disconnect-VIServer
.You can copy and paste this script into a PowerShell or PowerCLI session, replacing
<vCenterServer>
with the address or hostname of your vCenter server. After running the script, it will display the NQN information for each ESXi host in the specified cluster.