$ServerName= read-host "Please enter your Server Name:" $UserName=read-host "Please enter your user name" $EncrPassword=Read-Host "Enter Password" -assecurestring $Password=[System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($EncrPassword)) $databaseName= read-host "Please enter your database Name" write-host "" $out="D:\tools\ExecutionLog.txt" $FolderPath= "D:\tools\test" $SQLFiles = Get-ChildItem $FolderPath | where {!$_.PsIsContainer} foreach($file in $SQLFiles) { write-host "" write-host $file $file.Name | Out-File -Filepath $out -append $file=$FolderPath+"\"+$file sqlcmd -U $UserName -P $Password -b -S $ServerName -d $databaseName -i $file if($LASTEXITCODE -eq 0) { write-host "" write-host "Success" "Success" | Out-File -FilePath $out -append "" | Out-File -FilePath $out -append write-host "" } else { Get-Content $out Get-Content $out | Out-File -FilePath $out -append "" | Out-File -FilePath $out -append } } Start-Process notepad -WindowStyle normal $out
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)