Page 1 of 1 1
Topic Options
#207436 - 2013-07-15 03:14 PM problems migrating code from VBS to kix
Sam_B Offline
Getting the hang of it

Registered: 2005-10-25
Posts: 68
Loc: Bern, Switzerland
I'm trying to implement a function that deletes a empty group from Active directory. I found below code but I'm unable to translate
 Code:
objOU.Delete "Group", "cn=" & strGroupCN & "" 


to Kix. Thank you for your support.

Full VB Code:

 Code:
Sub DelGroup 
 
Dim objOU 
 
'WScript.Echo strOU 
'WScript.Echo strGroupCN 
Set objOU = GetObject(strOU) 
objOU.Delete "Group", "cn=" & strGroupCN & "" 
WScript.Echo strGroupName & " (CN=" & strGroupCN & ") has been deleted." 
 
Set ObjOU = Nothing 
strGroupCN = "" 
 
End Sub

Top
#207437 - 2013-07-15 04:27 PM Re: problems migrating code from VBS to kix [Re: Sam_B]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Give this a whirl. Don't have AD here so it's untested. Just put in the OU and Group CN in that first line.

 Code:
$RC = DelGroup("OU", "GroupCN Path")

If $RC = 0
   ? "Group was been deleted successfully."
Else
   ? "Group was Not been deleted.  Error: "+$RC
Endif

get $

Function DelGroup($strOU, $strGroupCN)
   Dim $objOU
   $objOU = GetObject($strOU)
   $objOU.Delete("Group","cn="+$strGroupCN)
   $DelGroup = @Error
   $objOU = ""
EndFunction


Edited by ShaneEP (2013-07-15 04:27 PM)

Top
#207447 - 2013-07-16 07:50 AM Re: problems migrating code from VBS to kix [Re: ShaneEP]
Sam_B Offline
Getting the hang of it

Registered: 2005-10-25
Posts: 68
Loc: Bern, Switzerland
Thanks ShaneEP for your post. During testing, Unfortunately, I got a runtime error at $objOU.Delete

ERROR : expected ')'!

Top
#207448 - 2013-07-16 08:19 AM Re: problems migrating code from VBS to kix [Re: Sam_B]
Sam_B Offline
Getting the hang of it

Registered: 2005-10-25
Posts: 68
Loc: Bern, Switzerland
Ok, got it. The proble was at GetObject() Function needs group name to be deleted and the OU of the group container.

 Code:
Function DeleteADGroup($StrGroup, $strGroupOU)
  Dim $objOU
  ;
  $DeleteADGroup = 0
  $objOU = GetObject("LDAP://" + $strGroupOU)
  If @ERROR
    Exit
  EndIf
  $objOU.Delete("Group", "cn=" + $StrGroup)
  If @ERROR = 0 
    $DeleteADGroup = 1
  EndIf
  $objOU = ""
EndFunction

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 793 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.133 seconds in which 0.075 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org