我希望通過在我的profile.ps1腳本中加載管理單元啓動PowerShell來爲我提供SQL Server PowerShell擴展。我找到一篇文章here,其中有一個腳本示例,演示瞭如何執行此操作,並且這在我的32位Windows XP盒子上正常工作。在SQLPS之外使用SQL Server 2008 R2 PowerShell擴展的問題
不幸的是,在我的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註冊管理單元」錯誤消息。
任何人有任何建議,我去哪裏?
由於我不想每次添加管理單元時都需要使用管理提升的PowerShell,所以我在您的博客中使用了SQLPS模塊方法,它的工作原理就像一個魅力!謝謝! – Irinotecan 2011-01-28 19:16:56
沒問題。我也更喜歡模塊方法,但請記住,只需要以管理員身份運行一次即可。之後,您可以運行add-pssnapin。 – 2011-01-29 03:22:53