locked
Powershell script to sync AD attribute into AD retrieve from Oracle DB RRS feed

  • Question

  • Hi,

    IT support team need to automate AD attribute sync using powershell script by comparing Reporting manager property with HR database & update.

    Requirement:
    We have HR Oracle Database which has all user detail at the same time there are some users whose reporting manager is not properly filled by Help-desk team into AD.
    So there is a requirement to retrieve all AD enabled users from AD then filter all users with Reporting manager attribute not present.Take that user & check reporting manager from HR oracle database & update that into AD.

    I have command with me to connect to Oracle DB & read also knew to retrieve AD attributes using below command. dont know how to compare logic.

      •    [Reflection.Assembly]::LoadFile("D:\app\admin\product\11.2.0\client_2\ODP.NET\bin\2.x\Oracle.DataAccess.dll")    
      •    Import-Module activedirectory  
      •    #Import Exchange server PSsnapin  
      •    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://Exchangeserver/PowerShell/ -Authentication Kerberos  
      •    Import-PSSession $Session  
      •    #connect to Oracle
           #creating password secure string
           #read-host -assecurestring | convertfrom-securestring | out-file C:\oraclecred.txt     $opw = get-content C:\oraclecred.txt | convertto-securestring 

    13.      $BasicString = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($opw)  

    14.      $oraclepassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BasicString)      

    15.     $oracleconstr = "User Id=User;Password=$oraclepassword;Data Source=HR"  

    16.     $oracleconnNew-Object Oracle.DataAccess.Client.OracleConnection($oracleconstr)  

    17.     $oracleconn.Open()  

    18.    

    19.     # Create a datareader for a Oracle statement    

    20.     $oracle = "Select * from SYSADM.PS_TERM_EMP"  

    21.     $oraclecommand = New-Object Oracle.DataAccess.Client.OracleCommand($oracle,$oracleconn)  

    22.     $reader=$oraclecommand.ExecuteReader()  

    23.    while ($reader.read())
    {

    $emp = $reader.GetString(0)
    $fn = $reader.GetString(2)
    $ln = $reader.GetString(4)
    $reportingmanager = $reader.GetDateTime(5)
    $user = Get-ADUser -Filter {employeeid -like $emp}  
    $date = Get-Date 
    }     

    Feel free to ask anything not clear or need more information.

    Wednesday, August 29, 2012 3:45 AM

Answers

  • How do we compare name in powershell.
    I mean if User name from AD is UserA & how to search it with all available character string UserA, UserB.................

    You have posted this same question twice.  I answered the same question on your other thread.

    Please do not post the same question multiple times.


    ¯\_(ツ)_/¯

    • Proposed as answer by Richard MuellerMVP Friday, September 21, 2012 4:55 PM
    • Marked as answer by IamMred Friday, September 21, 2012 6:30 PM
    Wednesday, August 29, 2012 11:59 AM

All replies

  • Is there a question?

    • Edited by jrv Wednesday, August 29, 2012 3:59 AM
    Wednesday, August 29, 2012 3:58 AM
  • yes in short can you help me in logic to 

    Take each user from AD with Reporting manager blank & connect to Oracle DB using last post, search user in Oracle DB. Retrieve Reporting manager property for user & update it into AD.

    How can i search user with matching string read from Oracle DB?
    Wednesday, August 29, 2012 4:10 AM
  • How do we compare name in powershell.
    I mean if User name from AD is UserA & how to search it with all available character string UserA, UserB.................
    Wednesday, August 29, 2012 5:18 AM
  • How do we compare name in powershell.
    I mean if User name from AD is UserA & how to search it with all available character string UserA, UserB.................

    You have posted this same question twice.  I answered the same question on your other thread.

    Please do not post the same question multiple times.


    ¯\_(ツ)_/¯

    • Proposed as answer by Richard MuellerMVP Friday, September 21, 2012 4:55 PM
    • Marked as answer by IamMred Friday, September 21, 2012 6:30 PM
    Wednesday, August 29, 2012 11:59 AM
  • thank you
    Thursday, August 30, 2012 3:44 AM
  • please do let us know where is this other thread. i'm also looking for same answers.
    Sunday, October 7, 2012 9:05 AM