如何暂停PowerShell以查看错误?
我尝试了下面链接中的每一条建议,但没有任何效果 这是我的密码:如何暂停PowerShell以查看错误?,powershell,Powershell,我尝试了下面链接中的每一条建议,但没有任何效果 这是我的密码: Read-Host -Prompt "Press Enter to continue" Invoke-Sqlcmd -Query "Select * from TBL_AGG_BOC" -ServerInstance "server_name\SQL2008" -Database "db_name" > "C:\Users\TBL_AGG_BOC.txt" Read-Host -Prompt "Press Enter to
Read-Host -Prompt "Press Enter to continue"
Invoke-Sqlcmd -Query "Select * from TBL_AGG_BOC" -ServerInstance "server_name\SQL2008" -Database "db_name" > "C:\Users\TBL_AGG_BOC.txt"
Read-Host -Prompt "Press Enter to continue"
脚本不断失败,它关闭得如此之快,以至于我看不到实际发生了什么。我怎样才能强迫它打开几秒钟,这样我就可以看到这里发生了什么
该文件已保存并命名为'test\u export.ps1'
,我右键单击该文件,然后单击'Run with PowerShell'
将其关闭。我没有这台机器的管理员权限。我希望这不是问题。我终于让它工作起来了。这是几件事的结合
Set ExecutionPolicy-Scope CurrentUser
RemoteSigned
并按Enter键设置执行策略-作用域CurrentUser
,然后按Enter键$server = "SERVERNAME\INSTANCE"
$database = "DATABASE_NAME"
$tablequery = "SELECT name from sys.tables"
# Declare connection variables
$connectionTemplate = "Data Source={0};Integrated Security=SSPI;Initial Catalog={1};"
$connectionString = [string]::Format($connectionTemplate, $server, $database)
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionString
$command = New-Object System.Data.SqlClient.SqlCommand
$command.CommandText = $tablequery
$command.Connection = $connection
# Load up the tables in a dataset
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $command
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$connection.Close()
# Loop through all tables and export a CSV of the table data
foreach ($Row in $DataSet.Tables[0].Rows)
{
$queryData = "SELECT * FROM [$($Row[0])]"
# Specify the output location of your dump file
$extractFile = "C:\mssql\export\$($Row[0]).csv"
$command.CommandText = $queryData
$command.Connection = $connection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $command
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$connection.Close()
$DataSet.Tables[0] | Export-Csv $extractFile -NoTypeInformation
}
结果是:$server=“SERVERNAME”
。不是这样:$server=“SERVERNAME\INSTANCE”
在我合并了这些更改后,一切正常。您也可以使用PowerShell运行它。在PowerShell提示符下键入要运行的
Invoke Sqlcmd
命令,然后按Enter
。读取错误。我在顶部添加了“Invoke Sqlcmd”,保存了文件,然后重新运行。同样的事情。它打开,几乎立即关闭。我所做的就是右键单击此ps1文件并单击“使用PowerShell运行”。我想可能还有另一个我遗漏的步骤。慢慢地重读并简单地按照Bills提示进行操作。PowerShell ISE将是最快的解决方案,Start-Transcript-Path“C:\transcripts\Transcript.txt”
也可能有帮助。