Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » Active Directory and PowerShell

Thread: Get AD SiteName of Computer

This question is not answered. Helpful answers available: 2. Answered answers available: 1.


Permlink Replies: 2 - Pages: 1 - Last Post: Dec 3, 2009 11:10 PM by: Shay Levy
Richard Farthing

Posts: 1
Registered: 12/3/09
Get AD SiteName of Computer
Posted: Dec 3, 2009 8:20 AM
 
  Click to reply to this thread Reply

Hi Everyone,

I am trying to get the AD Sitename of a computer, I know how to do it in VBS and WSH but finding it really hard to get this information for powershell.

Thanks


Shay Levy


Posts: 1,919
Registered: 1/31/08
Re: Get AD SiteName of Computer
Posted: Dec 3, 2009 1:35 PM   in response to: Richard Farthing
 
  Click to reply to this thread Reply

You have few options:

1. run locally

$obj = new-object -com ADSystemInfo

$type = $obj.gettype()
$type.InvokeMember("sitename","GetProperty",$null,$obj,$null)


2. query the registry. The site info is cached under:

HKLM:\System\CurrentControlSet\Services\Netlogon\Parameter\DynamicSiteName


3. A function I keep in my profile to get the site name remotley (requires nltest):

function Get-ADComputerSite($ComputerName)
{
 $site = nltest /server:$ComputerName /dsgetsite
 if($LASTEXITCODE -eq 0){ $site[0] }
}





Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
Shay Levy


Posts: 1,919
Registered: 1/31/08
Re: Get AD SiteName of Computer
Posted: Dec 3, 2009 11:10 PM   in response to: Richard Farthing
 
  Click to reply to this thread Reply

One more :)

[System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite()



Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar
Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums