我正在PowerShell ISE中编写脚本,并使用Invoke-Sqlcmd。在执行该命令之后,Powershell会话切换到sqlps会话(PS SQLSERVER:>),并且我不能第二次执行脚本。我必须退出PowerShell ISE并重新启动它。
所以我的问题是:如何从sqlp切换回常规ps,或者如何防止Invoke-Sqlcmd切换会话。
Invoke-Sqlcmd -ServerInstance $server -Database master -Username $user -Password $password -InputFile $file `
-ErrorAction Stop -OutputSqlErrors $true -Variable $variable
这不起作用:
Push-Location
Invoke-Sqlcmd -ServerInstance $server -Database master -Username $user -Password $password -InputFile $file `
-ErrorAction Stop -OutputSqlErrors $true -Variable $variable
Pop-Location
发布于 2014-06-11 23:30:43
sqlps
模块的行为是将您留在它创建的psdrive
中。我相当确定,人们已经要求微软解决这个问题,因为它非常恼人和破坏性。
PowerShell 3.0引入的自动导入模块使得这一点更加烦人,因为您甚至可能在事后才意识到您正在导入模块。
当我使用sqlps
时,我显式地导入它,这样我就可以控制我的工作目录,如下所示:
push-location
import-module sqlps -disablenamechecking
pop-location
这将使您在加载模块后返回到以前的目录。
非常晚的编辑:随着SQL Server Management Studio 2016的到来,我们有了一个新的PowerShell模块,sqlserver
,它取代了sqlps
并解决了这个问题。
发布于 2014-06-11 23:31:29
今天在SuperUser上也有一个类似的问题:https://superuser.com/questions/767427/stuck-in-powershell-sqlserver
您应该能够直接返回到C:
https://stackoverflow.com/questions/24164826
复制相似问题