Powershell: Get FQDN Hostname

后端 未结 15 1651
长发绾君心
长发绾君心 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:06

    How about: "$env:computername.$env:userdnsdomain"

    This actually only works if the user is logged into a domain (i.e. no local accounts), logged into the same domain as the server, and doesn't work with disjointed name space AD configurations.

    Use this as referenced in another answer:

    $myFQDN=(Get-WmiObject win32_computersystem).DNSHostName+"."+(Get-WmiObject win32_computersystem).Domain
    

    Write-Host $myFQDN

提交回复
热议问题