sql-server-2008 – 在SQLPS之外使用SQL Server 2008 R2 PowerSh
当我通过加载我的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:UsersxxxxDocumentsWindowsPowerShellprofile.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:SOFTWAREMicrosoftPowerShell1ShellIds Microsoft.SqlServer.Management.PowerShell.sqlps' because it does not exist. At C:UsersxxxxDocumentsWindowsPowerShellprofile.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 Server100ToolsBinn" 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转换成一个模块.我有博客文章: SQL Server 2012的更新 – 现在发布可以安装的sqlps模块,而不是上述博客:http://www.microsoft.com/en-us/download/details.aspx?id=35580 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |