Temp

From vwiki
Revision as of 13:47, 7 May 2013 by Sstrutt (talk | contribs) (xf)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<###################################################################################################################

Symbox User Migration Utility script

By Simon Strutt - May 2013

Version 0.1

- Initial creation
                                                                                                                                                                                                                                        1. >

$Symbox_Svr = "tnssymbox" $Symbox_Db = "symbox" $Symbox_Db_U = "root" $Symbox_DB_P = "dobrutro"

$logfile = "symbox_users.log"

$ShortLoop = $true

  1. Pre-amble ------------------------------------------------------------------------------------------------------------------------------

. .\lib\standard.ps1

Start-Transcript $logfile

Import-Module ActiveDirectory

  1. Connect to Symbox database

$DB = Connect-MySQL($Symbox_Db_U, $Symbox_DB_P, $Symbox_Svr, $Symbox_Db) if (!$DB) {

   Log ("Connection to database failed") 1
   Exit

}

  1. Get list of users in database

$Users = Execute-MySQLQuery ("SELECT * FROM tbl_users;") if ($Users.count -gt 1) {

   Log ("Got " + $Users.count + " users from Symbox db to review/process")

} else {

   Log ("Error getting users from database") 1
   Exit

}

foreach ($user in $Users) {

   if (!$user.user_id) {
       Continue
   }
   Log ("Processing user_id " + $user.user_id + ", user_login " + $user.user_login)
   $AdUser = Get-ADUser -Filter {Description -like ("* [" + $user.user_login + " | *")}
   if (!$AdUser) {
       Log ("User login not found in AD as EU imported login")
       Continue
   }
   $query = "UPDATE tbl_users SET user_login=" + $AdUser.SamAccountName + " WHERE user_id=" + $user.user_id + ";"
   Log $query
   Execute-MySQLNonQuery($query)
   if ($ShortLoop) {
       Log ("Breaking out of user processing...")
       Break
   }

}

Disconnect-MySQL