Monday, August 1, 2016

How to find vCenter info of a vm if you lost the records

clear
Add-PSSnapin VMware.VimAutomation.Core
$Admin ="tech-jockey\admin"
$Password = Get-Content c:\vccred\credential\cred.txt | convertto-securestring
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $Admin, $Password

$vc="vc1-name","vc2-name","vc3-name","vc4-name" # if you have 100 vc put those names here

foreach($item in $vc)
{
Connect-VIServer $item -SaveCredentials -Credential $Credential
}
clear
$inpt= Read-Host "Enter vm name to search:"
$vmm=get-vm $inpt.ToString()
$ht= Get-VMHost -name $vmm.Host
$silo= Get-Cluster -name $ht.parent
$srvid=$silo.Client.ServerUri
$len= $srvid.length -4
echo "VM Name"
echo $vmm.name
echo "======================"
echo "Esxi Host Name"
echo $vmm.host.Name
echo "======================"
echo "vCenter Name"
echo $srvid.Substring(4,$len)

No comments:

Post a Comment

Thanks for showing interest in tech-jockey.

Content of this blog has been moved to GITHUB

Looking at current trends and to make my content more reachable to people, I am moving all the content of my blog https://tech-jockey.blogsp...