[DllImport("netapi32.dll", SetLastError=true,CharSet=CharSet.Unicode)]
static extern UInt32 NetValidateName(string lpServer,string lpName, string lpAccount,string lpPassword, int NameType);
static extern UInt32 NetValidateName(string lpServer,string lpName, string lpAccount,string lpPassword, NET_SETUP_NAMETYPE NameType);
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class NetworkUtil
{
[DllImport("Netapi32.dll",CharSet=CharSet.Unicode)]
public static extern UInt32 NetValidateName(string lpServer,string lpName,string lpAccount,string lpPassword,
int NameType);
}
ENUM NET_SETUP_NAMETYPE{
NetSetupUnknown,
NetSetupMachine,
NetSetupWorkgroup,
NetSetupDomain,
NetSetupNonExistentDomain,
NetSetupDnsMachine}
Do you know one? Please contribute it!
Most useful NameType's are 1 and 3 which will allow you to see if the name is in use.
Please add some!
using System;
using System.Runtime.InteropServices;
public class NetworkUtil
{
[DllImport("Netapi32.dll",SetLastError=true,CharSet=CharSet.Unicode)]
public static extern UInt32 NetValidateName(string lpServer,string lpName, string lpAccount,string lpPassword, int NameType);
static void Main()
{
UInt32 rtn = NetValidateName(null, "jrich523.wordpress.com", null, null, 3);
Console.WriteLine(rtn);
Console.ReadKey();
}
}
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class NetworkUtil
{
[DllImport("Netapi32.dll",CharSet=CharSet.Unicode)]
public static extern UInt32 NetValidateName(string lpServer,string lpName,string lpAccount,string lpPassword,
int NameType);
}
"@
Function Test-NetBIOSName{
param([string] $Name, [int] $NameType)
[NetworkUtil]::NetValidateName($null,$name,$null,$null,$NameType)
}
#TEST
Test-NetBIOSName “myserver” 1