PowerCLI

 View Only
  • 1.  Retrieve hostname from fqdn

    Posted Sep 07, 2011 12:22 PM

    Hi again guys,

    Is there a simple way to return a hosts' short hostname from fqdn?

    For example If I:

    Connect-VIServer host1.domain.com

    then the value of ($vmhost = Get-VMHost) will be host1.domain.com and I would like to create a new variable containing just host1.

    I think I need to use the Powershell split() method with "." as a delimeter, but as yet i've not figured out how exactly to do it.

    Incidentally, are all Powershell methods (such as split() and toupper() ) available in PowerCLI be default, or can I invoke them somehow?

    Thanks,


    Dan



  • 2.  RE: Retrieve hostname from fqdn

    Posted Sep 07, 2011 01:18 PM

    Worked this one out:

    $vmhost = Get-VMHost

    $hostname = $vmhost.name.split(".")[0]

    Cheers,

    Dan



  • 3.  RE: Retrieve hostname from fqdn

    Posted Sep 07, 2011 01:24 PM

    Great you found the solution yourself.

    All these methods come with the type String, so yes, they are always available.