-1

Using a PowerShell script I'm trying to execute SqlPackage.exe to update a database. The problem is that it spawns a new CMD window and I can't capture the output effectively.

Here is my script:

&$SqlPackage "/Action:Script", "/SourceFile:$($Environment.PackageFile)", "/Profile:$($Environment.PublishProfile)", "/OutputPath:$($Environment.ScriptFile)";

where SqlPackage = "SQLPackage\SqlPackage.exe";.

Strangely when I execute the script on a Windows 2008 R2 web server the output is inline with the PowerShell output, which is ideally what I want. On my Windows 7 machine it spawns a new CMD window.

How can I route the output to the PowerShell window all the time, or at least pipe to another file?

Edit

Full solution with waiting for process to finish:

$p = Start-Process $SqlPackage -ArgumentList @("/Action:Script", "/SourceFile:$($Environment.PackageFile)", "/Profile:$($Environment.PublishProfile)", "/OutputPath:$($Environment.ScriptFile)") -NoNewWindow -Wait -Passthru
$p.WaitForExit()
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
user917170
  • 1,591
  • 15
  • 28

1 Answers1

2

You should be able to get the result you are looking for if you use Start-Process with the -NoNewWindow parameter:

Start-Process $SqlPackage -ArgumentList @("/Action:Script", "/SourceFile:$($Environment.PackageFile)", "/Profile:$($Environment.PublishProfile)", "/OutputPath:$($Environment.ScriptFile)") -NoNewWindow

If you need to direct the output to a file you can also use the -RedirectStandardOutput / -RedirectStandardError parameters of Start-Process

Paul
  • 5,524
  • 1
  • 22
  • 39
  • Perfect! I need to wait for the process to finish before executing the next statement, I presume that is possible too? I've tried -Wait but it doesn't seem to work. – user917170 May 07 '15 at 02:27