Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
Active Directory
Get AD Site Of Computer
Last Post 04 Dec 2009 02:08 AM by
Richard Farthing
. 3 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
Richard Farthing
New Member
Posts:2
03 Dec 2009 07:44 AM
Hi Everyone,
I am trying to determine the AD Site of the logged on computer so that I can set the print server for that site.
Thanks
Shay Levy
PowerShell MVP, Admin
Veteran Member
Posts:1362
03 Dec 2009 01:29 PM
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
Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter:
@ShayLevy
Shay Levy
PowerShell MVP, Admin
Veteran Member
Posts:1362
03 Dec 2009 11:04 PM
One more :)
[System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite()
Shay Levy
Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter:
@ShayLevy
Richard Farthing
New Member
Posts:2
04 Dec 2009 02:08 AM
Thanks Shay that worked fine. I used option 1.
Thanks
You are not authorized to post a reply.
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
Active Directory
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2