Page 1 of 1 1
Topic Options
#177669 - 2007-07-09 09:44 PM user to computer desc
ack2000 Offline
Fresh Scripter

Registered: 2007-07-09
Posts: 8
Before I write it. Has anyone created a script to take the username and write to that computer account's description in AD.

Thanks

Makes finding users easier.

Top
#177670 - 2007-07-09 10:20 PM Re: user to computer desc [Re: ack2000]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Some stuff like it but not sure I've seen an exact post with code to do it.
Top
#177688 - 2007-07-10 03:56 PM Re: user to computer desc [Re: NTDOC]
ack2000 Offline
Fresh Scripter

Registered: 2007-07-09
Posts: 8
I am use to writing for ASP not kix. I need a little help this keeps erroring on line 15 expected ')'!

Dim $oRootDSE, $sDomainADsPath, $ldapPath, $filter, $entry, $searcher, $result, $DirectoryServices
$oRootDSE = GetObject("LDAP://RootDSE")
$sDomainADsPath = "LDAP://" & $oRootDSE.Get("defaultNamingContext")
$ldapPath = $sDomainADsPath
$filter = String.Format("(&(objectCategory=computer)(name=" & @wksta &"))")
$entry = New $DirectoryServices.DirectoryEntry($ldapPath)
$searcher = New $DirectoryServices.DirectorySearcher($entry, $filter, New String() {"description", "ADsPath"})

$result as $DirectoryServices.SearchResult = $searcher.FindOne()
If Not IsNothing($result) Then
If ($result.Properties.Contains("description")) Then
$TxtDesc1 = $result.Properties("description")(0)
End If

If ($result.Properties.Contains("AdsPath")) Then
$lblAdsPath = $result.Properties("AdsPath")(0)
End If


End If


Dim $objParent As New $DirectoryServices.DirectoryEntry($lblAdsPath, "administrator", "password", $DirectoryServices.AuthenticationTypes.Secure)
$objParent.Properties("description").Value = (@FULLNAME)
$objParent.CommitChanges()

Top
#177689 - 2007-07-10 04:13 PM Re: user to computer desc [Re: ack2000]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You can start by taking out the space between END and IF. This is not VBS.

Also there is no THEN.


Edited by Les (2007-07-10 04:15 PM)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#177690 - 2007-07-10 04:42 PM Re: user to computer desc [Re: ack2000]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
And replace the & signs with the + signs \:\)

Also this won't work:
 Code:
 Dim $objParent As New $DirectoryServices.DirectoryEntry($lblAdsPath, "administrator", "password", $DirectoryServices.AuthenticationTypes.Secure)


Kix does not support type declaration as of yet. (Something I hope to be implemented in the future though)


Edited by apronk (2007-07-10 04:44 PM)

Top
#177691 - 2007-07-10 05:25 PM Re: user to computer desc [Re: ack2000]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
 Originally Posted By: ack2000

 Code:
$result as $DirectoryServices.SearchResult = $searcher.FindOne()
If Not IsNothing($result) Then
I don't think KiX knows what to do with "AS".
Do you have a UDF called IsNothing()?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#177692 - 2007-07-10 05:36 PM Re: user to computer desc [Re: Arend_]
ack2000 Offline
Fresh Scripter

Registered: 2007-07-09
Posts: 8
if i set static fields i have no problem (see below). But my AD has computers in different OU's So i need to look up the adspath. I have tried a few different methods but have not success. any help on a searcher that works with kix would nice.

Dim $oRootDSE, $sDomainADsPath, $ldapPath, $filter, $entry, $searcher, $result, $DirectoryServices, $objParent
$oRootDSE = GetObject("LDAP://RootDSE")
$sDomainADsPath = "LDAP://" & $oRootDSE.Get("defaultNamingContext")
$ldapPath = $sDomainADsPath
$filter = String.Format("(+(objectCategory=computer)(name="+ @WKSTA +"))")

$objParent = GetObject("LDAP://CN=compname,OU=folder1,OU=folder0,DC=domain,DC=com")
$objParent.Put("description", "@fullname")
$objParent.SetInfo

Top
#177694 - 2007-07-10 05:38 PM Re: user to computer desc [Re: ack2000]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Could you please use the code tags when posting code.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#177695 - 2007-07-10 05:43 PM Re: user to computer desc [Re: ack2000]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
the TranslateName UDF will help you out.
Top
#177696 - 2007-07-10 05:47 PM Re: user to computer desc [Re: Mart]
ack2000 Offline
Fresh Scripter

Registered: 2007-07-09
Posts: 8
will do.
Top
#177698 - 2007-07-10 06:16 PM Re: user to computer desc [Re: ack2000]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Still too much VBS in there.

$sDomainADsPath = "LDAP://" & $oRootDSE.Get("defaultNamingContext")
$ldapPath = $sDomainADsPath
$filter = String.Format("(+(objectCategory=computer)(name="+ @WKSTA +"))")
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#177699 - 2007-07-10 07:22 PM Re: user to computer desc [Re: Les]
ack2000 Offline
Fresh Scripter

Registered: 2007-07-09
Posts: 8
filter was left from failed search, thanks. wasnt able to find TranslateName UDF sample that was mention above.


 Code:
 
	Dim $oRootDSE,  $sDomainADsPath, $ldapPath, $filter, $entry, $searcher, $result, $DirectoryServices, $objParent
	$oRootDSE = GetObject("LDAP://RootDSE")
	$sDomainADsPath = "LDAP://" + $oRootDSE.Get("defaultNamingContext")
	$ldapPath = $sDomainADsPath
	$objParent = GetObject("LDAP://CN=softsol000340d,OU=Software_Solutions_Workstations,OU=DCAS,DC=dcas1,DC=com")
	$objParent.Put("description", "@fullname")
	$objParent.SetInfo





trying to do a record set search but it fails everytime at while not $orecordset.eof

 Code:
	Dim $oRootDSE, $sDomainADsPath, $oCon, $oRecordSet, $oCmd, $sGroup, $sProperties, $aDescription, $aMember, $iCount

$oRootDSE = GetObject("LDAP://RootDSE")
$sDomainADsPath = "LDAP://" & $oRootDSE.Get("defaultNamingContext")
$oCon = CreateObject("ADODB.Connection")
$oRecordSet = CreateObject("ADODB.Recordset")
$oCmd = CreateObject("ADODB.Command")


	;$oRootDSE = Nothing
	$oCon.Provider = "ADsDSOObject"
	$oCon.Open("ADProvider")
	$oCmd.ActiveConnection = $oCon
	$sProperties = "ADsPath,description"
	$sGroup = "*"
	$oCmd.CommandText = "<"+$sDomainADsPath+">;(+(objectClass=computer)(cn="+@WKSTA+"));"+$sProperties+";subtree"
	$oRecordSet = $oCmd.Execute
	;$oRecordSet.MoveFirst
		While Not $oRecordSet.EOF ;fails right here
	$icount = $oRecordSet.Fields("ADsPath").Value
		End While
        Dim $oRootDSE,  $sDomainADsPath, $ldapPath, $filter, $entry, $searcher, $result, $DirectoryServices, $objParent
	  $oRootDSE = GetObject("LDAP://RootDSE")
        $sDomainADsPath = "LDAP://" + $oRootDSE.Get("defaultNamingContext")
        $ldapPath = $sDomainADsPath
        $filter = String.Format("(+(objectCategory=computer)(name="+ @WKSTA +"))")
        $objParent = GetObject("$icount")
        $objParent.Put("description", "@fullname")
        $objParent.SetInfo
	$oRecordSet.Close
	$oCon.Close
	$oRecordSet = Nothing
	$oCon = Nothing



Edited by ack2000 (2007-07-10 07:28 PM)

Top
#177700 - 2007-07-10 07:31 PM Re: user to computer desc [Re: ack2000]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
 Quote:
wasnt able to find TranslateName UDF

http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Board=7&Number=83021

You still haven't removed the VBS nomenclature mentioned above.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#177701 - 2007-07-10 08:21 PM Re: user to computer desc [Re: Les]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
What I don't understand is since you seem to be more familiar with VBS than KiX, why are you writing this in KiX? Actually, there is a lot I don't understand about what you are trying to do.
Is this to be a central admin script and if so, how are you matching up the user to the computer?
If this is a user logon script, will the user have the needed perms to write the computer description in AD?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#177702 - 2007-07-10 09:18 PM Re: user to computer desc [Re: Les]
ack2000 Offline
Fresh Scripter

Registered: 2007-07-09
Posts: 8
working code: takes user name and windows version and places it in the AD computer description.
 Code:
$Names = TranslateName (3, "", 3, @Domain + "\" + @wksta + "$", "1") 
Dim $x
	$objParent = GetObject("LDAP://" + $Names[1])
	$objParent.Put("description",""+@fullname+ " " +@PRODUCTTYPE+"")
	$objParent.SetInfo


Function TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)
  Dim $NameTranslate, $Error, $ErrorText, $ReturnNameArray[12], $GetNameArray, $value
  $Error = 0
  $ErrorText = ""
  $ReturnName = ""
  $NameTranslate = CREATEOBJECT ("NameTranslate")
  $Error = @error
  $ErrorText = @serror
  if $Error = 0
    $NameTranslate.Init ($InitType, $BindName)
    $Error = @error
    $ErrorText = @serror
    if $Error = 0
      $NameTranslate.Set ($LookupNameType, $LookupName)
      $Error = @error
      $ErrorText = @serror
      if $Error = 0        
Dim $index
        $GetNameArray = split($ReturnNameType, ",")
        for $index=0 to ubound($GetNameArray)
          $value = $GetNameArray[$index]
          $ReturnNameArray[$value] = $NameTranslate.Get($value)
        next
      else
        WriteLog("TranslateName SET Error: (" + $Error + ") " + $ErrorText)
        exit $Error
      endif
    else
      WriteLog("TranslateName INIT Error: (" + $Error + ") " + $ErrorText)
      exit $Error
    endif
  else
    WriteLog("TranslateName CREATEOBJECT Error: (" + $Error + ") " + $ErrorText)
    exit $Error
  endif
  $TranslateName = $ReturnNameArray
  Exit 0
Endfunction

Top
#177703 - 2007-07-10 09:26 PM Re: user to computer desc [Re: Les]
ack2000 Offline
Fresh Scripter

Registered: 2007-07-09
Posts: 8
kix is what we a currently using for login script. so I am only changing what I need to right now.
the reason for this it attempt to see how many non exist computer are floating around in AD (just recently start working here) and there are more computer names the actual users....So its a user script and i was going to attempt to spefiy the admin, password in the getobject of the code. this way I wont have to worry about permissions. This only temporary anyways.

Top
#177704 - 2007-07-10 09:31 PM Re: user to computer desc [Re: ack2000]
ack2000 Offline
Fresh Scripter

Registered: 2007-07-09
Posts: 8
permission were not an issue. Just tested with Domain user and it updated the Description. This might be a flaw in the this domains AD. I will have to research.


BTW Thank you for all your help.


Edited by ack2000 (2007-07-10 09:42 PM)

Top
#177705 - 2007-07-10 09:44 PM Re: user to computer desc [Re: ack2000]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I'm surprised that a regular user can write to that field.

If you are looking for stale computer accounts, the machine account password age is a pretty good indicator. I just bring up a list of computers in Hyena and sort on the password age column. In the old days, I was doing it using the MachAcctPWAge utility written by Howard Bullock. In fact when we did our NT to AD migration, we used it and/or Hyena to ferret out thousands of stale accounts.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#177724 - 2007-07-11 08:32 AM Re: user to computer desc [Re: Les]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
 Originally Posted By: Les
I'm surprised that a regular user can write to that field.


As am I, writing to those type of fields usually require at least "Account Operator" privileges.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 1539 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.06 seconds in which 0.021 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