/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" MSH Community Workspace, TFSC provider and videos "," more Monad scripts, and a bit more CSV "," working with CSV files in MSH (part two) "," working with CSV files in MSH (part one) "," and another source for MSH scripts is born "," VBscript hosting in MSH, Inputbox in Monad part 2 "," Some Monad Com hacks "," It's busy at the Monad front "," Monad Remoting "," How MSH Works "," ")

Saturday, April 08, 2006


access ADSI WinNT provider from Monad Part 2

In my first post about accessing the WinNt provider from MSH, MSH access NT provider I used an ugly workaround using inline VB.NET code.

I found a better solution (inspired by James truher's get-lastlogon example on MonadSource)

This one first loads the microsoft.visualbasic namespace,
then uses the GetObject method of the microsoft.visualbasic.interaction class to get the Com-Object.

after that I will use the InvokeMember Method on the type, using Reflection binding flags to call the method or Property.

# Get-Admins.msh 
# gets the users in the admininstrators group
# using Visualbasic namespace, reflection and the WinNT provider
# /\/\o\/\/ 2006 
# http://mow001.blogspot.com 


$Group = [microsoft.visualbasic.interaction]::GetObject("WinNT://./administrators,group",$null)
$GroupType = $Group.gettype()

$im = [reflection.bindingflags]::InvokeMethod
$gp = [reflection.bindingflags]::GetProperty
"Members :";""
$members = $GroupType.invokemember("members",$im,$null,$Group,$null)
$members | foreach  {
  $userType = $_.gettype()
  $userType.invokemember("name",$gp,$null,$_ ,$null)
  $userType.invokemember("AdsPath",$gp,$null,$_ ,$null)

It's still a bit "Hacked" way to do this, but I think it's much better as the VB.NET one ;-)

This makes it realy possible to make much better use of the WinNT provider from MSH
We are still "working in the Dark", as we can not use GM, but You can use the ADSI WinNT Provider doc's in the SDK on MSDN to get help on the properties and methods.


Greetings /\/\o\/\/

Tags :

Anonymous Anonymous
We really need WinNT provider. This is cool but I still do not feel comfortible. Maybe I should wait for version 2.
Anonymous Tin
I do a search on ADSI WINNT and found this: http://www.thescripts.com/forum/thread235336.html
It actually work when I do this:
$rootEntry = new-Object System.DirectoryServices.DirectoryEntry("WinNT://.")
$rootEntry.get_Children()|%{$_.get_Name(), $_.get_Path()}
Post a Comment

<< Home


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.
Web mow001.blogspot.com

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