Tuesday, 4 January 2011


This script uses WMI to get the name of a computer's domain then displays the name.
This script is a re-write of an MSDN sample, using PowerShell.
File Name : Get-ComputerDomain.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : PowerShell Version 2.0
This script posted to:
MSDN sample posted tot:
PSH [C:\foo]: .\Get-ComputerDomain.ps1
System Name: WIN7
Domain: cookham.net
Psh[Cookham8]> .\Get-ComputerDomain.ps1 cookham2
System Name: COOKHAM2
Domain: cookham.net
The name of the computer whose domain name to be displayed. Default is localhost.

# Parameter block
param (
$comp = "."

# Get WMI Object
$system = Get-WmiObject -class Win32_ComputerSystem -ComputerName $comp

# Display results
"System Name: {0}" -f $System.Name
"Domain: {0}" -f $System.Domain