#109249 - 2003-12-02 05:59 PM
Re: New functionality in Win32Admin3
Jose
Seasoned Scripter
Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Howard: What I have made here is a script that dumps all the users properties to an excel sheet. What I tried to say above was that the only left appart from Win32Admin is how I get the users array (for UserGetInfo) to get the properties. Code: ;************************************************************* ; VARIABLES ;************************************************************* $server ="??" ;PDC server ;************************************************************* ; HOWARD DLL OBJECT ;************************************************************* Break ON $ = SetOption ("WrapAtEol" ,"On" ) ? "KiXtart version = " @KIX $Win32Admin = CreateObject ("Win32Admin" ) If VarTypeName ($Win32Admin ) < > "Object" ? "@serror" EndIf ;************************************************************* ; CREATES EXCEL OBJECT ;************************************************************* $oXL = CreateObject ("EXCEL.application" ) $oXL.Visible = 1 ; make Excel visible to the user $rc =$oXL.Workbooks.Add ; add a new workbook $array = "Name" , "Group" , "Full Name" , "Profile" , "Script Path" , "Home dir drive" , "Home dir" , "Group" , "Comment" $oXL.Range ("A1:I1" ).Value = $array ;add some columns ;************************************************************* ; GETS $USERS ARRAY WITH GetUserList FUNCTION (WINNT OBJECT) ;************************************************************* $ = GetUserList (@DOMAIN ) $cant =Ubound ($Users ) ;************************************************************* ; GETS UserGetInfo ;************************************************************* For $i =0 to $cant $UserInfo = $Win32Admin.UserGetInfo ("$server" , $Users [$i ]) If @error = 0 $keys = $UserInfo.keys EndIf For Each $key in $keys $fullname = $UserInfo.full_name $Value = $UserInfo.Get ($key ) Select Case $Key ="name" AND $key < > "" $name =$value Case $Key ="primary_group_id" AND $key < > "" $Group = $Win32Admin.GetUserGroupFromRID ("$server" ,$value ) Case $key ="full_name" AND $key < > "" $full_name =$value Case $Key ="profile" AND $key < > "" $profile =$value Case $key ="script_path" AND $key < > "" $script_path =$value Case $key ="home_dir_drive" AND $key < > "" $home_dir_drive =$value Case $key ="home_dir" AND $key < > "" $home_dir =$value Case $Key ="primary_group_id" AND $key < > "" $Group = $Win32Admin.GetUserGroupFromRID ("$server" ,$value ) Case $key ="comment" AND $key < > "" $comment =$value EndSelect ;************************************************************* ; ADD VALUES TO EXCELL SHEET ;************************************************************* $oXL.Cells (($i +2 ),1 ).Value = $name $oXL.Cells (($i +2 ),2 ).Value = $Group $oXL.Cells (($i +2 ),3 ).Value = $full_name $oXL.Cells (($i +2 ),4 ).Value = $profile $oXL.Cells (($i +2 ),5 ).Value = $script_path $oXL.Cells (($i +2 ),6 ).Value = $home_dir_drive $oXL.Cells (($i +2 ),7 ).Value = $home_dir $oXL.Cells (($i +2 ),8 ).Value = $Group $oXL.Cells (($i +2 ),9 ).Value = $comment Next ;************************************************************* ; CLEAR VARS ;************************************************************* $name ="" $Group ="" $full_name ="" $profile ="" $script_path ="" $home_dir_drive ="" $home_dir ="" $Group ="" $comment ="" Next ;************************************************************* ; ORDERS SHEET ;************************************************************* $oXL.Range ("A1:I1" ).Font.Bold = 1 $rc =$oXL.Range ("A1:I1" ).EntireColumn.AutoFit $oXL.UserControl = 1 ;************************************************************* ; GetUserList FUNCTION GETS ARRAY OF ALL DOMAIN USERS ;************************************************************* Function GetUserList ($DomainName ) Dim $count [5000 ] ;Create domain object $Domain = GetObject ("WinNT://" + $DomainName + ",domain" ) ;Set container object equal to domain object. $Container = $Domain ;Iterates through EVERY object in the domain. Those ;objects that match the class are included in the array. For Each $User In $Container If $User.Class = "User" $count [$x ] = $User.Name $x = $x + 1 EndIf Next ;Resize the array appropriately ReDim Preserve $count [$x - 1 ] ;Set $Users (global variable) equal to $count (local variable) $Users = $count ;Object cleanup $Domain = 0 $Container = 0 EndFunction This has been very helpfull cause appart from backing up the database I saw lots of silly errors that I had. Thanks Howard.
_________________________
Life is fine.
Top
Moderator: Shawn , ShaneEP , Ruud van Velsen , Arend_ , Jochen , Radimus , Glenn Barnas , Allen , Mart
0 registered
and 484 anonymous users online.