Powershell: Get FQDN Hostname

后端 未结 15 1654
长发绾君心
长发绾君心 2021-01-30 12:24

I want to retrieve the FQDN name of windows server via powershell script. I have found 2 solution so far:

$server =  Invoke-Command -ScriptBlock {hostname}
         


        
15条回答
  •  说谎
    说谎 (楼主)
    2021-01-30 13:20

    I use the following syntax :

    $Domain=[System.Net.Dns]::GetHostByName($VM).Hostname.split('.')
    $Domain=$Domain[1]+'.'+$Domain[2]
    

    it does not matter if the $VM is up or down...

提交回复
热议问题