I created this script in Powershell
to read a DB record and create a
hash of it salty and insert it back
in a table, good script
works fine the way I need, but
what sticks is the delay 9 million record
two days. I need if anyone has any
command that could make it faster to things.
Who has little record and want to use
this script are comfortable it works.
$user = "user"
$pwd = "pws"
$database = "bdd"
$SqlServer = "round"
$SqlLogs = "T_Powershll"
$Date = (Get-Date -format g)
$SqlConnection = New-Object system.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString ="Server=$dataSource;uid=$user; pwd=$pwd;Database=$database;Integrated Security=False;"
$SqlConnection2 = New-Object system.Data.SqlClient.SqlConnection("Server=$dataSource;uid=$user; pwd=$pwd;Database=$database;Integrated Security=False;")
$seq=1
$fim=9561421
While ($seq -le $fim){
$SqlCommandText = "Select Cartao from T_Powershll_base where Id_seq= $seq "
$SqlConnection.Open()
$SqlConnection2.Open()
$SqlCmd = New-Object Data.SqlClient.SqlCommand($SqlCommandText, $SqlConnection)
$sqlcmd2 = $SqlConnection2.createcommand()
$Reader = $SqlCmd.ExecuteReader()
$SqlData = @( )
while ($Reader.Read())
{
$SqlData += "" | Select-Object `
@{ n = 'Cartao' ; e = { $Reader["Cartao"].ToString() } }
}
$Reader.Close()
$sha1 = New-Object System.Security.Cryptography.SHA1CryptoServiceProvider;
$sha1.Initialize();
$Salgado="710000hhgiiAAAhhhhooohzaqnpa
epszx7w2soPmdfapa)gbbakkazwq
"
$cart=$SqlData.Cartao
$cart2=[System.Text.Encoding]::ASCII.GetBytes($cart.PadRight(32,'_'));
$lim4=[System.Convert]::FromBase64String($Salgado.ToString());
$ab =$sha1.ComputeHash($cart2+$lim4);
$HASH="{0}" -f [system.BitConverter]::ToString($ab)-replace "-",""
$sqlcmd2.CommandText = "INSERT INTO $SQLLogs (Cartao, Cartao_Hash) VALUES ('$($SqlData.Cartao)', '$($HASH)')"
$Results = $SqlCmd2.ExecuteNonQuery()
$seq++
$SqlConnection.close()
$SqlConnection2.close()
}
TKS.