Categories

Test for domain membership

Quick function to determine if a given machine is in a domain or workgroup

function test-domain{             
[CmdletBinding()]             
param (             
[parameter(Position=0,            
   Mandatory=$true,            
   ValueFromPipeline=$true,             
   ValueFromPipelineByPropertyName=$true)]            
   [string]$computer="."             
)             
BEGIN{}#begin             
PROCESS{            
 Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computer |            
 select Name, Domain            
            
}#process             
END{}#end            
            
}


Feed the function a computer name or IP address and it will return the name and domain. If the computer is in the domain we get the full domain name – if its in a workgroup we get the workgroup name (WORKGROUP by default)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>