工作中用到的脚本,查用户所在的组,下面的代码已经测试通过。
注意:要得到MemberOf的属性值,在Javascrip中要将它的值转换成VBArray型。
<%
var strContainer = "OU=系统维护室,OU=网管中心";
var strName = "徐中";
var objRootDSE = GetObject("LDAP://rootDSE");
var objUser = GetObject("LDAP://cn=" + strName + "," + strContainer + "," + objRootDSE.Get("defaultNamingContext"));
var objGroupList = objUser.GetEx("MemberOf");
var strGroup;
var GroupArray = new VBArray( objGroupList ) ;
var jsGroupArray = GroupArray.toArray() ;
for( strGroup in jsGroupArray )
{
var adGroupPath = ("LDAP://"+jsGroupArray[strGroup]);
var adGroup = GetObject( adGroupPath );
var adGroupName = adGroup.CN;
adGroupName = adGroupName.toLowerCase();
Response.Write( adGroupName + "<br>");
}
%>
参考:http://groups.msn.com/windowsscript/general.msnw?action=get_message&mview=0&ID_Message=13007&ID_CLast=13016&CDir=1<%
var strContainer = "OU=程序开发";
var strName = "徐中";
var objRootDSE = GetObject("LDAP://rootDSE");
var objUser = GetObject("LDAP://cn=" + strName + "," + strContainer + "," + objRootDSE.Get("defaultNamingContext"));
// My ADsPath = LDAP://CN= 徐中,OU=程序开发,DC=nmc,DC=ln,DC=cmcc
// objRootDSE.Get("defaultNamingContext") 能得到 DC=nmc,DC=ln,DC=cmcc
var objGroupList = objUser.GetEx("MemberOf");
var strGroup;
var GroupArray = new VBArray( objGroupList ) ;
var jsGroupArray = GroupArray.toArray() ;
for( strGroup in jsGroupArray )
{
var adGroupPath = ("LDAP://"+jsGroupArray[strGroup]);
var adGroup = GetObject( adGroupPath );
var adGroupName = adGroup.CN;
adGroupName = adGroupName.toLowerCase();
Response.Write( adGroupName + "
");
}
%>
文章来源:http://ms.mblogger.cn/xuzhong/posts/16820.aspx