1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| $startTime = (Get-Date)
$username = "xxxxx"
$password = "xxxxxxxxxx"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
Start-Process powershell.exe -Credential $cred
IF (!(Get-Module -Name sqlps))
{
Write-Host 'Loading SQLPS Module' -ForegroundColor DarkYellow
Push-Location
Import-Module sqlps -DisableNameChecking
Pop-Location
}
$localScriptRoot = "C:\TSQL\Insertion Distind_importation_tampon\"
$Server = "DWH"
$scripts = Get-ChildItem $localScriptRoot | Where-Object {$_.Extension -eq ".sql"}
foreach ($s in $scripts)
{
Write-Host "Running Script : " $s.Name -BackgroundColor DarkGreen -ForegroundColor White
$script = $s.FullName
try
{
Invoke-Sqlcmd -ServerInstance $Server -InputFile $script -ErrorAction Stop
}
Catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
}
}
$endTime = (Get-Date)
$ElapsedTime = (($endTime-$startTime))
'Duration: {0:mm} min {0:ss} sec' -f $ElapsedTime |
Partager