sql-server-2008 – 在SQLPS之外使用SQL Server 2008 R2 PowerShell扩展的问题

当我通过加载我的profile.ps1脚本中的管理单元启动Power Shell时,我希望可以使用sql Server PowerShell扩展.我发现了一篇文章 here,其中包含一个脚本示例,显示了如何执行此操作,这在32位Windows XP框上工作正常.

不幸的是,在我的64位Windows 7机器上,这爆发了.如果我尝试使用64位PowerShell启动这个脚本,我得到:

Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2.
At C:\Users\xxxx\Documents\WindowsPowerShell\profile.ps1:84 char:13
+ Add-PSSnapin <<<<  sqlServerCmdletSnapin100
+ CategoryInfo          : InvalidArgument: (sqlServerCmdletSnapin100:String
[Add-PSSnapin],PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

如果我在32位PowerShell中运行,我得到:

Get-ItemProperty : Cannot find path 'HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds \Microsoft.sqlServer.Management.PowerShell.sqlps' because it does not exist.
At C:\Users\xxxx\Documents\WindowsPowerShell\profile.ps1:39 char:29
+     $item = Get-ItemProperty <<<<  $sqlpsreg
+ CategoryInfo          : ObjectNotFound: (HKLM:\SOFTWARE\...owerShell.sqlps:String) [Get-ItemProperty],ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand

如果可能,我希望能够在64位PowerShell中运行它.为此,我跟踪了我以为是Powershell扩展dll和64位的管理员提升的PowerShell我跑了:

cd "C:\Program Files (x86)\Microsoft sql Server\100\Tools\Binn"
installutil Microsoft.sqlServer.Management.PSProvider.dll
installutil Microsoft.sqlServer.Management.PSSnapins.dll

没有骰子.虽然installutil似乎表明成功,但是当我运行脚本时,仍然会收到“没有为Windows PowerShell版本2注册的管理单元”错误消息.

任何人有什么建议,我从哪里去?

解决方法

我在x64机器上使用这个脚本没有问题. x86调用的问题是脚本会查找x64实例上只能从x64 PowerShell访问的注册表项.对于x64调用,您可以尝试注册snapins,因为这是您收到的错误消息.以管理员身份运行…

改变这个:

cd $sqlpsPath
Add-PSSnapin sqlServerCmdletSnapin100
Add-PSSnapin sqlServerProviderSnapin100

到这个:

cd $sqlpsPath
$framework=$([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())
Set-Alias installutil "$($framework)installutil.exe"
installutil Microsoft.sqlServer.Management.PSSnapins.dll
installutil Microsoft.sqlServer.Management.PSProvider.dll
Add-PSSnapin sqlServerCmdletSnapin100
Add-PSSnapin sqlServerProviderSnapin100

一个更好的解决方案不是使用add-pssnapin而是将sqlps转换成一个模块.我有博客文章
http://sev17.com/2010/07/making-a-sqlps-module/

sql Server 2012的更新 – 现在发布可以安装的sqlps模块,而不是上述博客http://www.microsoft.com/en-us/download/details.aspx?id=35580

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...