Populating the address book

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SoCi0pAtH
    Technician
    • May 2018
    • 18

    Populating the address book

    We have Konica all in one copiers in the office. We heavily use the scan feature and copy the file to the users home drive. With 60+ copiers and 700+ users in 40 offices maintaining the address books on each printer is a daily chore..

    My goal is to automate this task as much as possible.

    Goal : Query AD for user information to build csv to import. Each office has its own OU in AD, so I should be able to create a seperate csv for each office based upon the OU.

    Challenges
    1. I'm not able to use the homedir attribute because its populated with a DFS link that the copiers cant support.
    2. Each site has its own DFS home dir server/host. Although there is a naming convention there are old servers that dont follow it.
    3. Home directories root are different for each site.
    4. Each site has its own AD service account to grant access to the users home drive.

    This is a NOT working work in progress

    The logic goes
    1. Query AD for list of OUs (sites)
    2. Create a file with the OU name
    3. Write column headers
    4. Populate user info
    5. Repeat until all AD OUs have been processed.

    Code:
    clsTaskkill /IM Excel.exe /F
    setlocal enabledelayedexpansion
    
    
    for /f "delims=" %%i in ('adfind ^-nodn ^-list ^-s one ^-soao ^-f objectclass^=OrganizationalUnit ^-b ^"OU^=Users^-Corporate^,OU^=UserAccounts^,DC^=mycompany^,DC^=int^" distinguishedname') do (
        for /f "delims=" %%v in ('adfind ^-f "%%i" ^-nodn ^-list name') do (
            echo Processing OU %%v
            )
        echo Abbreviated name,Destination type,Search key,E-Mail: E-Mail Address,SMB: Host Address,SMB: File Path,SMB: User ID > %%v.csv
        for /f "delims=" %%j in ('adfind ^-soao ^-f objectclass^=person ^-b ^"%%i^" ^-nodn ^-list sAMAccountName') do (
            set abbreviated=
            set first=
            set last=
            set destination=SMB
            set mail=
            set smbhost=CRP^-SRV^-FILE1
            set smbpath=user\
            set smbid=CRP-PRT
            echo  processing AD %%i
            for /f "delims=" %%k in ('adfind ^-nodn ^-nocsvheader ^-csv ^-f ^"sAMAccountName^=%%j^" displayName') do set abbreviated=%%k
            for /f "delims=" %%m in ('adfind ^-nodn ^-nocsvheader ^-list ^-f ^"sAMAccountName^=%%j^" givenname') do set first=%%m
            for /f "delims=" %%q in ('adfind ^-nodn ^-nocsvheader ^-list ^-f ^"sAMAccountName^=%%j^" sn') do set last=%%q
            for /f "delims=" %%r in ('adfind ^-nodn ^-nocsvheader ^-list ^-f ^"sAMAccountName^=%%j^" mail') do set mail=%%r
                echo !abbreviated!,!destination!,search key,!mail!,!smbhost!,!smbpath!!first!.!last!,!smbid!
                echo !abbreviated!,!destination!,,!mail!,!smbhost!,!smbpath!!first!.!last!,!smbid! >> %%v.csv
            )
        start c:\scripts\%%v.csv     
        )

    Once I get it working I'm going to write it in Powershell.

    Any suggestions for a command line utility to upload the csv's to the printers would be great.
  • SoCi0pAtH
    Technician
    • May 2018
    • 18

    #2
    Re: Populating the address book

    Example output

    Abbreviated name,Destination type,Search key,E-Mail: E-Mail Address,SMB: Host Address,SMB
    "Sean Smith",SMB,search key,sean.brennan@mycompany.net,CRP-SRV-FILE1,user\Sean.smith,CRP-PRT

    Comment

    • Copier Addict
      Aging Tech

      Site Contributor
      10,000+ Posts
      • Jul 2013
      • 13040

      #3
      Re: Populating the address book

      Try Pagescope Data Administrator. With it you are able to manage multiple MFPs at the same time.
      It is a free download from KonMin. Just google it.

      Comment

      • SoCi0pAtH
        Technician
        • May 2018
        • 18

        #4
        Re: Populating the address book

        Originally posted by copier addict
        Try Pagescope Data Administrator. With it you are able to manage multiple MFPs at the same time.
        It is a free download from KonMin. Just google it.
        I have it, but with 60+ copiers I'm hoping to make this a completely automated task.

        Comment

        • copyman
          Owner / Technician

          Site Contributor
          2,500+ Posts
          • Sep 2005
          • 4217

          #5
          Re: Populating the address book

          Depends on the model of the machines.

          Comment

          • SoCi0pAtH
            Technician
            • May 2018
            • 18

            #6
            Re: Populating the address book

            Originally posted by copyman
            Depends on the model of the machines.

            Which ones, and using what utility?

            Comment

            • SoCi0pAtH
              Technician
              • May 2018
              • 18

              #7
              Re: Populating the address book

              The latest.....Still a lot of junk code and few test lines.. but its %95 working....

              Code:
              echo
              cls
              Taskkill /IM Excel.exe /F
              setlocal enabledelayedexpansion
              
              
              for /f "delims=" %%i in ('adfind ^-nodn ^-list ^-s one ^-soao ^-f objectclass^=OrganizationalUnit ^-b ^"OU^=Users^-Corporate^,OU^=UserAccounts^,DC^=mycompany^,DC^=int^" OU') do (
                  echo =============================Processing OU %%i========================================
                  echo Abbreviated name,E-Mail: E-Mail Address,SMB: Host Address,SMB: File Path,SMB: User ID,SMB: Password > "%%i.csv"
                  for /f "delims=" %%j in ('adfind ^-soao -b "OU=%%i,OU=Users-Corporate,OU=UserAccounts,DC=mycompany,DC=int" ^-f objectclass^=person ^-list sAMAccountName') do (
                      set abbreviated=
                      set first=
                      set last=
                      set destination=SMB
                      set mail=
                      set password="7EV!9%"
                      set smbhost=CRP
                      set smbpath=users\
                      set smbid=CRP-PRT
                      echo  Adding %%j to site %%i
                      for /f "delims=" %%k in ('adfind -b ^"OU^=Users^-Corporate^,OU^=UserAccounts^,DC^=mycompany^,DC^=int^" ^-nodn ^-nocsvheader ^-list ^-f ^"sAMAccountName^=%%j^" displayName') do set abbreviated=%%k
                      for /f "delims=" %%m in ('adfind -b ^"OU^=Users^-Corporate^,OU^=UserAccounts^,DC^=mycompany^,DC^=int^" ^-nodn ^-nocsvheader ^-list ^-f ^"sAMAccountName^=%%j^" givenname') do set first=%%m
                      for /f "delims=" %%q in ('adfind -b ^"OU^=Users^-Corporate^,OU^=UserAccounts^,DC^=mycompany^,DC^=int^" ^-nodn ^-nocsvheader ^-list ^-f ^"sAMAccountName^=%%j^" sn') do set last=%%q
                      for /f "delims=" %%r in ('adfind -b ^"OU^=Users^-Corporate^,OU^=UserAccounts^,DC^=mycompany^,DC^=int^" ^-nodn ^-nocsvheader ^-list ^-f ^"sAMAccountName^=%%j^" mail') do set mail=%%r
                          echo !abbreviated!,!mail!,!smbhost!,!smbpath!!first!.!last!\scans,!smbid!,!password!
                      Echo
                          echo !abbreviated!,!mail!,!smbhost!,!smbpath!!first!.!last!\scans,!smbid!,!password!>> "%%i.csv"
                      )
                  rem "C:\Program Files\Microsoft Office 15\root\Office15\excel.exe" "c:\scripts\%%i.csv"      
                  )

              Comment

              • rrrohan
                Service Manager

                Site Contributor
                1,000+ Posts
                • Sep 2011
                • 1971

                #8
                Re: Populating the address book

                Why not enable LDAP search and just print instructions on how to search and register your email address.

                Comment

                • NeoMatrix
                  Senior Tech.

                  2,500+ Posts
                  • Nov 2010
                  • 3514

                  #9
                  Re: Populating the address book

                  Originally posted by SoCi0pAtH
                  The latest.....Still a lot of junk code and few test lines.. but its %95 working....

                  Code:
                  echo
                  cls
                  Taskkill /IM Excel.exe /F
                  setlocal enabledelayedexpansion
                  
                  
                  for /f "delims=" %%i in ('adfind ^-nodn ^-list ^-s one ^-soao ^-f objectclass^=OrganizationalUnit ^-b ^"OU^=Users^-Corporate^,OU^=UserAccounts^,DC^=mycompany^,DC^=int^" OU') do (
                      echo =============================Processing OU %%i========================================
                      echo Abbreviated name,E-Mail: E-Mail Address,SMB: Host Address,SMB: File Path,SMB: User ID,SMB: Password > "%%i.csv"
                      for /f "delims=" %%j in ('adfind ^-soao -b "OU=%%i,OU=Users-Corporate,OU=UserAccounts,DC=mycompany,DC=int" ^-f objectclass^=person ^-list sAMAccountName') do (
                          set abbreviated=
                          set first=
                          set last=
                          set destination=SMB
                          set mail=
                          set password="7EV!9%"
                          set smbhost=CRP
                          set smbpath=users\
                          set smbid=CRP-PRT
                          echo  Adding %%j to site %%i
                          for /f "delims=" %%k in ('adfind -b ^"OU^=Users^-Corporate^,OU^=UserAccounts^,DC^=mycompany^,DC^=int^" ^-nodn ^-nocsvheader ^-list ^-f ^"sAMAccountName^=%%j^" displayName') do set abbreviated=%%k
                          for /f "delims=" %%m in ('adfind -b ^"OU^=Users^-Corporate^,OU^=UserAccounts^,DC^=mycompany^,DC^=int^" ^-nodn ^-nocsvheader ^-list ^-f ^"sAMAccountName^=%%j^" givenname') do set first=%%m
                          for /f "delims=" %%q in ('adfind -b ^"OU^=Users^-Corporate^,OU^=UserAccounts^,DC^=mycompany^,DC^=int^" ^-nodn ^-nocsvheader ^-list ^-f ^"sAMAccountName^=%%j^" sn') do set last=%%q
                          for /f "delims=" %%r in ('adfind -b ^"OU^=Users^-Corporate^,OU^=UserAccounts^,DC^=mycompany^,DC^=int^" ^-nodn ^-nocsvheader ^-list ^-f ^"sAMAccountName^=%%j^" mail') do set mail=%%r
                              echo !abbreviated!,!mail!,!smbhost!,!smbpath!!first!.!last!\scans,!smbid!,!password!
                          Echo
                              echo !abbreviated!,!mail!,!smbhost!,!smbpath!!first!.!last!\scans,!smbid!,!password!>> "%%i.csv"
                          )
                      rem "C:\Program Files\Microsoft Office 15\root\Office15\excel.exe" "c:\scripts\%%i.csv"      
                      )
                  What is the "adfind" trying to execute ?

                  Is "adfind" a konmin or macintosh command for searching a string ?
                  You appear to be "escaping ^" a lot of strings in the "For /F" function.
                  You may be able to reduce the "for function" escapes to a simplified variable set directly.

                  Example only . Have you tried using:
                  Any string line of text found with adfind "-" will be broken into single tokens at each "-"

                  for /f "tokens=1-9, delims=-" %%i do ( 'adfind /sw "any string"' ) do (

                  set abbreviated=%%i
                  set first= %%j
                  set last= %%k
                  set destination=%%l
                  set mail=%%m
                  set password=%%n
                  set smbhost=%%o
                  set smbpath=%%p
                  set smbid=%%q

                  )

                  Token variables are case sensitive eg. "for /f %%i" is not the same as "for /f %%I"
                  Every "for" loop loses all token %%? values once outside the bracket delimits of the "for /f" loop.
                  The for %%? are only local vars while inside the "for /f" loop. You cannot access these values, thought it will store the last only value until the batch file terminates with "EndLocal" command.
                  Endlocal is automatically implied at the end of the batch file.


                  Post a sample/portion of a typical input *.txt or *.csv file to the forum.
                  You've already shown the format of the *.csv output file.
                  I may get a spare moment to throw some batch code together.
                  Last edited by NeoMatrix; 06-08-2018, 12:25 PM.
                  Inauguration to the "AI cancel-culture" fraternity 1997...
                  •••••• •••[§]• |N | € | o | M | Δ | t | π | ¡ | x | •[§]••• ••••••

                  Comment

                  • SoCi0pAtH
                    Technician
                    • May 2018
                    • 18

                    #10
                    Re: Populating the address book

                    Originally posted by rrrohan
                    Why not enable LDAP search and just print instructions on how to search and register your email address.
                    Using this method to populate the address book means the users can scan to their home directory with about 5 buttons to press. Searching would be atleast 30. Our users complain a lot LOL

                    Comment

                    • SoCi0pAtH
                      Technician
                      • May 2018
                      • 18

                      #11
                      Re: Populating the address book

                      Sample of the output

                      Comment

                      • SoCi0pAtH
                        Technician
                        • May 2018
                        • 18

                        #12
                        Re: Populating the address book

                        Originally posted by NeoMatrix
                        What is the "adfind" trying to execute ?

                        Is "adfind" a konmin or macintosh command for searching a string ?
                        AdFind

                        Comment

                        • NeoMatrix
                          Senior Tech.

                          2,500+ Posts
                          • Nov 2010
                          • 3514

                          #13
                          Re: Populating the address book

                          Originally posted by SoCi0pAtH
                          I have download an run the command line Adfind app. I don't have an LDAP server that I can test with Adfind.

                          Being a command line app the standard output of Adfind can be redirected to a typed file. Eg. adfind [s/w params] > temp.txt

                          The redirected temp.txt can then be used inside any batch file commands directly.

                          Example only:
                          ----------------------------------------
                          echo off
                          cls
                          type nul > addr.txt

                          setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS

                          Adfind [s/w params] > temp.txt

                          for /f "tokens=1-9*,delims=," %%i in ('type temp.txt') do (

                          echo %%i,%%j,%%k,%%l,%%m,%%n,%%o,%%p,%%r >> addr.txt

                          )
                          endlocal


                          ---------8<-----------------------------

                          Note the commas "," between the echo line variable tokens.
                          Leave out the variable tokens that are not required in the final "addr.txt" output file.

                          You're on the right track....


                          A quick look at the adfind help file shows there are a few output file options.
                          Some of the options allow for customised *.csv file output.
                          Inauguration to the "AI cancel-culture" fraternity 1997...
                          •••••• •••[§]• |N | € | o | M | Δ | t | π | ¡ | x | •[§]••• ••••••

                          Comment

                          • SoCi0pAtH
                            Technician
                            • May 2018
                            • 18

                            #14
                            Re: Populating the address book

                            Originally posted by NeoMatrix
                            I have download an run the command line Adfind app. I don't have an LDAP server that I can test with Adfind.

                            Being a command line app the standard output of Adfind can be redirected to a typed file. Eg. adfind [s/w params] > temp.txt

                            The redirected temp.txt can then be used inside any batch file commands directly.

                            Example only:
                            ----------------------------------------
                            echo off
                            cls
                            type nul > addr.txt

                            setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS

                            Adfind [s/w params] > temp.txt

                            for /f "tokens=1-9*,delims=," %%i in ('type temp.txt') do (

                            echo %%i,%%j,%%k,%%l,%%m,%%n,%%o,%%p,%%r >> addr.txt

                            )
                            endlocal


                            ---------8<-----------------------------

                            Note the commas "," between the echo line variable tokens.
                            Leave out the variable tokens that are not required in the final "addr.txt" output file.

                            You're on the right track....


                            A quick look at the adfind help file shows there are a few output file options.
                            Some of the options allow for customised *.csv file output.
                            If you look at my original post/code you'll see I'm already outputting to a CSV file. Its a little hard to see because i'm naming the file with a var that is populated by the name of the OU being processed.


                            1st for - ADFIND queries a base OU one level deep only for names of OU's.
                            I write the header/column names for my CSV (each one) and name the csv after the OU being processed
                            For Each OU name a second for loop is called that queries the OU for a list of User objects
                            For each User object several ADFINDS are called that populate the user data in Vars
                            When the user data is collected its written to my CSV file in CSV format.

                            This repeats until all OU's and their users have been processed. I end up with about 40 csv files, named after the OU/Office. I can then connect to the printer and upload the correct CSV with the correct users for the location.

                            The script is working now, I'm having an issue with OU's that have spaces in the name that I havent had time to workout. IF the OU has spaces in the name the second ADFIND fails

                            Comment

                            • SoCi0pAtH
                              Technician
                              • May 2018
                              • 18

                              #15
                              Re: Populating the address book

                              Originally posted by NeoMatrix
                              I have download an run the command line Adfind app. I don't have an LDAP server that I can test with Adfind.
                              Online LDAP Test Server - Forum Systems

                              Comment

                              Working...