Temp
Jump to navigation
Jump to search
<###################################################################################################################
Symbox User Migration Utility script
By Simon Strutt - May 2013
Version 0.1
- Initial creation
- >
$Symbox_Svr = "tnssymbox" $Symbox_Db = "symbox" $Symbox_Db_U = "root" $Symbox_DB_P = "dobrutro"
$logfile = "symbox_users.log"
$ShortLoop = $true
- Pre-amble ------------------------------------------------------------------------------------------------------------------------------
. .\lib\standard.ps1
Start-Transcript $logfile
Import-Module ActiveDirectory
- 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
}
- 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