/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Get Current dir in MSH consoleTtitle "," MSH ASCII translator "," red MSH> prompt "," Monad presentation on PDC05 available, "," A guided tour of the MSH on arstechnica.com "," Lets Query WMI from MSH "," Getting and using a SecurityPrincipal from MSH "," Line Breaks "," MSH Clipboard part 2 (of 3 ?) "," MSH TakeOwner working "," ")

Friday, October 28, 2005

 


AD Infastructure exploring with MSH



while working in AD with MSH, I noticed the new (.NET 2.0) namesspace :

System.DirectoryServices.ActiveDirectory

there are some very Handy classes there, that make working with AD,(especialy the infrastructure part) a lot easier.
Some Examples below (but do a get-member on the Object, there are a lot more handy properties and methods here !!)

gr /\/\o\/\/



#Get ADSI connection to the CurrentDomain
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain()

#get some info

$dom.Forest.name
$dom.DomainMode

#get domain password policy

$dom.GetDirectoryEntry().pwdHistoryLength

#Get trust relations

$dom.GetAllTrustRelationships() fl

#find a domaincontroller and connect to it
$dc = $dom.finddomaincontroller()

# Get the Forrest
$for = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()

#Find ONE GC
$gc = $for.FindGlobalCatalog()

#find all GC in yourSite
$for.FindAllGlobalCatalogs("YourSite")

# without using a DomainObject.
$dt = [System.DirectoryServices.ActiveDirectory.DirectoryContexttype]"domain"
$c = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext($dt)
$dc::findone($c)



Comments:
Anonymous Anonymous
I found these very useful. Thankyou.
I used [reflection.assembly]::loadwithpartialname("system.directoryservices.activedirectory") to load into Monad as these classes aren't loaded by default. I can't figure out how load without using the loadwithpartialname() option. As this is being deprecated I wondered if you knew how to do this.

Thanks
 
Blogger /\/\o\/\/
I still use the LoadWithPartialName,
for ease, but you can find more info about doing it the right way here :

http://www.leeholmes.com/blog/HowDoIEasilyLoadAssembliesWhenLoadWithPartialNameHasBeenDeprecated.aspx

gr /\/\o\/\/

PS system.directoryservices should be imported standard
 
Blogger /\/\o\/\/
I tested it a bit,
the system.directoryservices.activedirectory
namespace is in the same assembly as system.directory services.

and this is allready imported so You dont need to load it, the [reflection.assembly]::loadwithpartialname does also not work

try this to list the loaded assemblies

("system.directoryservices.activedirectory")
[system.threading.thread]::getdomain().GetAssemblies()

but you should be able to use this without loading any extra assemblies.

gr /\/\o\/\/
 
Anonymous Anonymous
Thanks for the info
 
Post a Comment



<< Home

Archives

October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Google
 
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?