Powershell: Get FQDN Hostname

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

    Here is a way to determine the FQDN of a server based on the "Name" and "DistinguishedName". Works for multiple domains:

    $server = Get-ADComputer serverName -Server domainName -Properties * | select Name, DistinguishedName
    $domain = $server.DistinguishedName -split ","
    $domain = $domain | ? {$_ -like 'DC=*'}
    $domain = $domain -join "."
    $domain = $domain -replace "DC="
    $FQDN = $server.Name + "." + $domain
    

提交回复
热议问题