I knew when I wrote this that I would have to rewrite it once I migrated to AD but I had to fix all the lost passwords before the migration. Well, I am now migrated to AD, so here is my first draft of the rewrite.

I will eventually change the methodology from using NetView2() to something like EnumOU() but for now there are not that many in the new domain.

One thing I found is that the "Comment" that NetView2() returns is not displayed either in Hyena or in ADUC. What does show in its stead is the "Description" field which is blank. I now write the "Comment" both to the INI file and to AD. Also if the "Description" exists in AD and does not match the server "Comment", I write the "Comment" to the computer.


; Script to reset passwords on remote machines
; Version 2.0
; Requires Kixtart 4.x
; by Les Ligetfalvy
;@error + '[' + @SError + ']' ?

break on
dim $,$computer,$domain,$comp,$ConfigINI,$ResultsINI,$exclude,$Month,$last,$RC[4]
dim $RenCmdPre,$RenCmdPost,$Pwd,$ShellCMD,$Comment,$ADProp,$adsComputer,$Desc,$ADdesc
$ = setoption('explicit','on')
$ = setoption('wrapateol','on')

$ConfigINI = @ScriptDir + '\config.ini'
$ResultsINI = @ScriptDir + '\results.ini'
$Month = @Month
$Pwd = ReadProfileString($ConfigINI,'Passwords',$Month)
$exclude = split(ReadProfileString($ConfigINI,'Exclude',''),chr(10))
$RenCmdPre = @ScriptDir + '\RenameAdmin.exe --computer '
$RenCmdPost = ' --pwd ' + $Pwd + ' --nolog --quiet'

for each $computer in netview2(@domain,1)
  $comp = split($computer,',')[0]
  $comment = split($computer,',')[1]
  If ascan($exclude,$comp) = -1 and left($comp,2) = 'FF'
    $rc = InContainer('ou=ff,ou=cacc,dc=cacc,dc=local','computer',$comp)
    If $rc[0] > 0
      $last = ReadProfileString($ResultsINI,$comp,'LastPwdChanged')
      If @error = 0 and $last <$Month
        $ADProp = GetObject('LDAP://'+$RC[3])
        $ADdesc = $ADProp.get('description')
        If $Comment <'' and $ADdesc <$Comment
          $ADProp.put('description',$comment)
          $ADProp.setinfo
          $ADProp = ''
          $ADdesc = $Comment
        endif
        If $ADdesc <'' and $Comment <$ADdesc
          $adsComputer = GetObject('WinNT://' + $Comp + '/LanmanServer')
            $adsComputer.Description = $ADdesc
            $adsComputer.SetInfo
            $adsComputer = ''
        endif 
        $ShellCMD = $RenCmdPre + $comp + $RenCmdPost 
        ;shell $ShellCMD
        If @error = 0
          $ = WriteProfileString($ResultsINI,$comp,'LastPwdChanged',$Month)
          $ = WriteProfileString($ResultsINI,$comp,'LastSeen',@Date + ', ' + @Time)
          $ = WriteProfileString($ResultsINI,$comp,'Comment',$Comment)
        else
          $ = WriteProfileString($ResultsINI,$comp,'LastError',@Date + ', ' + @Time + ' - ' + @SError)
        endif
      else
        $ = WriteProfileString($ResultsINI,$comp,'LastSeen',@Date + ', ' + @Time)
        $ = WriteProfileString($ResultsINI,$comp,'Comment',$Comment)
      endif
    endif
  endif
next
;==============================
function NetView2(optional $domainoptional $commentflag)
;http://81.17.37.55/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=12;t=000202
  dim $array[255]
  dim $redim$i$j$tempfile
  dim $filehandle$retcode
  dim $name$comment$line
  $redim = 255
  $i = 0
  $j = 0
  $tempfile = '%temp%\netview.tmp'
  if $domain
    $domain = '/domain:'+trim($domain)
  endif
  if vartype($commentflag)
    $commentflag=val($commentflag)
  else
    $commentflag=0
  endif
  if exist($tempfile)
    del $tempfile
  endif
  shell '%comspec% /c net view $domain >"'+$tempfile+'"'
  if @error = 0
    $filehandle=1
    do
      $retcode=open($filehandle,$tempfile)
      $filehandle=$filehandle+1
    until $retcode=0 or $filehandle=11
    select
    case $retcode=-3
      exit 4
    case $retcode=-2
      exit 6
    case $retcode=-1
      exit 123
    case $retcode=0
      $filehandle=$filehandle-1
    case $retcode>0
      exit @ERROR
    case $filehandle=11
      exit 4
    endselect
    for $j = 1 to 5
      $line = readline($filehandle; skip headings
    next
    while @error = 0
      $nametrim(substr($line,3,instr($line,' ')-1))
      $comment = trim(right($line,len($line)-instr($line,' ')))
      if $commentflag
        $array[$i]=$name+','+$comment
      else
        $array[$i]=$name
      endif
      $i=$i+1
      if $i = $redim
        $redim=$redim*2
        redim preserve $array[$redim]
      endif
      $line = readline($filehandle)
    loop
    $retcode=close($filehandle)
    del $tempfile
    if $i
      redim preserve $array[$i-4]
      $netview2 = $array
      exit @error
    endif
  endif
  $netview2 = 0
  exit @error
endfunction
;--------------------------------------------------------------------------------
;FUNCTION         InContainer()
;http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000179
;AUTHOR           Howard A. Bullock (hbullock@tycoelectronics.com)
;
;VERSION          1.3 (modified by Les Ligetfalvy)
;
Function InContainer ($Container$NameType$Name)
   Dim $CurrentContainer$Name1$Name2

   select
      case $NameType = 'Computer'  $Name1 = @Domain + '\' + $Name + '$'
      case $NameType = 'User'      $Name1 = @LDomain + '\' + @UserID
      case 1                       $Name1 = ''
   endselect

   if $Name1 <''
      $Name2 = TranslateName (3''3$Name11)
      if $Name2[1] = 0
         $CurrentContainer = substr($Name2[0], instr($Name2[0], ',')+1)
         select
            case $CurrentContainer=$Container  $InContainer = 1$Name2[1], $Name2[2], $Name2[0]
            case instr($Name2[0], $Container$InContainer = 2$Name2[1], $Name2[2], $Name2[0]
            case 1                             $InContainer = 0$Name2[1], $Name2[2]
         endselect
      else
         $InContainer = -2$Name2[1], $Name2[2]
      endif
   else
      $InContainer = -10'',''
   endif
EndFunction
 
;--------------------------------------------------------------------------------

;FUNCTION         TranslateName()
;http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000178
;AUTHOR           Howard A. Bullock (hbullock@tycoelectronics.com)
;
;VERSION          2.0
;
Function TranslateName ($InitType$BindName$LookupNameType$LookupName$ReturnNameType)

   Dim $NameTranslate$ReturnName$Error$ErrorText

   $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
            $ReturnName = $NameTranslate.Get($ReturnNameType)
            $Error = @error
            $ErrorText = @serror
         endif
      endif
   endif
   $TranslateName = $ReturnName$Error$ErrorText
Endfunction

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.