internal/Resolve-NetBiosName.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Function Resolve-NetBiosName
{
 <#
.SYNOPSIS
Internal function. Takes a best guess at the NetBIOS name of a server.
 #>

[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[Alias("ServerInstance", "SqlInstance")]
[object]$SqlServer,
[System.Management.Automation.PSCredential]$SqlCredential
)

$server = Connect-SqlServer -SqlServer $SqlServer -SqlCredential $SqlCredential
$servernetbios = $server.ComputerNamePhysicalNetBIOS

if ($servernetbios -eq $null)
{
$servernetbios = ($server.name).Split("\")[0]
$servernetbios = $servernetbios.Split(",")[0]
}

return $($servernetbios.ToLower())
}