微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/mssql/82004.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐