Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server Powershell脚本无法记录sql Server 2012数据库“输出窗口”消息_Sql Server_Powershell_Powershell 2.0_Powershell 3.0 - Fatal编程技术网

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

Sql server Powershell脚本无法记录sql Server 2012数据库“输出窗口”消息,sql-server,powershell,powershell-2.0,powershell-3.0,Sql Server,Powershell,Powershell 2.0,Powershell 3.0,我正在运行此powershell脚本以针对我的数据库SQLServer2012运行sql脚本,所有脚本都已成功运行。 问题在日志文件中,未记录与成功创建的表或更新的一行相关的日志。只有select语句的输出记录在那里 请建议 push-location; Import-Module sqlps; Pop-Location; foreach ($f in Get-ChildItem -path "D:\Mywork\powersh\SQLDump\" -Filter *.s

我正在运行此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;

隐马尔可夫模型。。。创建表时,普通sqlcmd或SSMS甚至不打印任何内容。您的脚本中是否有打印语句或类似的内容,使其能够这样做?至于更新,这很奇怪。如果是我,我会使用带有-o参数的sqlcmd来指定输出文件,而不是调用sqlcmd。我正在通过powershell编写脚本,为多个客户端创建数据库结构,需要知道是否所有sql语句都成功运行,如果没有,那么我想知道哪些查询失败。现在我的查询中没有打印语句。这很公平,但我上面的评论仍然有效。在使用-AbortOnError调用sqlcmd或使用-b调用纯旧sqlcmd执行脚本后,请检查$?变量如果最后一个命令成功,则包含$true;如果没有成功,则包含$false。