Powershell脚本无法记录sql server 2012数据库的“输出窗口”消息

时间:2014-10-30 06:43:41

标签: sql-server powershell powershell-v2.0 powershell-v3.0

我正在运行这个powershell脚本来对我的数据库SQLServer2012运行sql脚本,所有脚本都运行成功。 问题出现在日志文件中,与"表相关的日志成功创建"或者"更新了一行"没有被记录。只有select语句的输出记录在那里。

请建议

   push-location;
   Import-Module sqlps;
   Pop-Location;
   foreach ($f in Get-ChildItem -path "D:\Mywork\powersh\SQLDump\" -Filter *.sql | sort-object ) 
   { 
     try
     {

     $timestamp = get-date -uformat '%Y%m%d%H%M%S%p';
     $out = "D:\Mywork\powersh\SQLDump\OUTPUT\" + $f.name.split(".")[0]+ "_" +$timestamp+ ".txt" ;

    $mydata = invoke-sqlcmd -InputFile $f.fullname -serverinstance MyServer\SQLEXPRESS -database AdventureWorks;
    $mydata | out-file -filePath $out;

    }
   catch {
   $out = "D:\Mywork\powersh\SQLDump\OUTPUT\ErrorLog"+ "_" +$timestamp+ ".txt" ;
   $error[0].Exception.GetType().FullName +"test" | out-file -filePath $out;
    }
  }
  remove-module sqlps;

0 个答案:

没有答案
相关问题