This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
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
[void][reflection.assembly]::LoadWithPartialName("microsoft.visualbasic")
$Group = [microsoft.visualbasic.interaction]::GetObject("WinNT://./administrators,group",$null)
$GroupType = $Group.gettype()
$im = [reflection.bindingflags]::InvokeMethod
$gp = [reflection.bindingflags]::GetProperty
"Group:";""
$GroupType.invokemember("name",$gp,$null,$Group,$null)
"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.
enjoy,
Greetings /\/\o\/\/
Tags : Monad msh