没有为 Windows PowerShell 版本 2 注册管理单元 [英] No snap-ins have been registered for Windows PowerShell version 2

查看:230
本文介绍了没有为 Windows PowerShell 版本 2 注册管理单元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在未安装 SQL Server Management Studio 但已安装 Microsoft SQL Server 2008 R2 SP2 功能包中的所有相关包的 Web 服务器上运行 Powershell 脚本.您需要安装这些小部件,以便 Powershell 能够运行 SQL 命令.

I am trying to run a Powershell script on a web server where SQL Server Management Studio is not installed but all pertinent packages from the Microsoft SQL Server 2008 R2 SP2 Feature Pack have been installed. You need to install those small bits and pieces in order for Powershell to be able to run SQL commands.

然后我运行了这个设置脚本,为使用 Powershell 运行的 SQL Server 命令准备环境:

Then I ran this setup script that preps your environment for SQL Server commands run with Powershell:

$ErrorActionPreference = "Stop"

$sqlpsreg="HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps"

if (Get-ChildItem $sqlpsreg -ErrorAction "SilentlyContinue")
{
    throw "SQL Server Powershell is not installed."
}
else
{
    $item = Get-ItemProperty $sqlpsreg
    $sqlpsPath = [System.IO.Path]::GetDirectoryName($item.Path)
}



/* Preload the assemblies. Note that most assemblies will be loaded when the provider
 is used. if you work only within the provider this may not be needed. It will reduce
 the shell's footprint if you leave these out.*/

$assemblylist =
"Microsoft.SqlServer.Smo",
"Microsoft.SqlServer.Dmf ",
"Microsoft.SqlServer.SqlWmiManagement ",
"Microsoft.SqlServer.ConnectionInfo ",
"Microsoft.SqlServer.SmoExtended ",
"Microsoft.SqlServer.Management.RegisteredServers ",
"Microsoft.SqlServer.Management.Sdk.Sfc ",
"Microsoft.SqlServer.SqlEnum ",
"Microsoft.SqlServer.RegSvrEnum ",
"Microsoft.SqlServer.WmiEnum ",
"Microsoft.SqlServer.ServiceBrokerEnum ",
"Microsoft.SqlServer.ConnectionInfoExtended ",
"Microsoft.SqlServer.Management.Collector ",
"Microsoft.SqlServer.Management.CollectorEnum"


foreach ($asm in $assemblylist)
{
    $asm = [Reflection.Assembly]::LoadWithPartialName($asm)
}


//Set variables that the provider expects (mandatory for the SQL provider)

Set-Variable -scope Global -name SqlServerMaximumChildItems -Value 0
Set-Variable -scope Global -name SqlServerConnectionTimeout -Value 30
Set-Variable -scope Global -name SqlServerIncludeSystemObjects -Value $false
Set-Variable -scope Global -name SqlServerMaximumTabCompletion -Value 1000


//Load the snapins, type data, format data

Push-Location
cd $sqlpsPath


Add-PSSnapin SqlServerCmdletSnapin100
Add-PSSnapin SqlServerProviderSnapin100 
Update-TypeData -PrependPath SQLProvider.Types.ps1xml  
update-FormatData -prependpath SQLProvider.Format.ps1xml  
Pop-Location

Add-PSSnapin SqlServerCmdletSnapin100,脚本失败并出现以下错误:

At Add-PSSnapin SqlServerCmdletSnapin100, the script fails with the following error:

尚未为 Windows PowerShell 版本 2 注册任何管理单元.在C:\Vantiv\Initialize-SqlpsEnvironment.ps1:75 字符:13+ 添加-PSSnapin <<<<SqlServerCmdletSnapin100 #-ErrorAction SilentlyContinue+ CategoryInfo : InvalidArgument: (SqlServerCmdletSnapin100:String) [Add-PSSnapin], PSArgumentException+ FullQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

No snap-ins have been registered for Windows PowerShell version 2. At C:\Vantiv\Initialize-SqlpsEnvironment.ps1:75 char:13 + Add-PSSnapin <<<< SqlServerCmdletSnapin100 #-ErrorAction SilentlyContinue + CategoryInfo : InvalidArgument: (SqlServerCmdletSnapin100:String) [Add-PSSnapin], PSArgumentException + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

我针对此错误进行了 Google 搜索,我找到的唯一解决方案是人们说我的 64 位 Powershell 控制台快捷方式指向 SysWOW64 目录而不是 System32.这不是我的情况.我的指向 System32.

I ran a Google search on this error and the only solution I could find was that people were saying my 64-bit Powershell Console shortcut was pointed to the SysWOW64 directory rather than the System32. This is not the case for me. Mine points to System32.

有什么想法吗?我需要做什么才能让 Powershell 注册这些管理单元?

Any ideas? What do I need to do to get Powershell to register those snap-ins?

推荐答案

如果你这样做:

Get-PSSnapin -Registered

您将获得一份现成的 PowerShell 管理单元列表(此处仅适用于 SQL):

you'll get a list of ready-to-use snap-ins for PowerShell (here just those for SQL) :

Name        : SqlServerCmdletSnapin100
PSVersion   : 2.0
Description : This is a PowerShell snap-in that includes various SQL Server cmdlets.

Name        : SqlServerProviderSnapin100
PSVersion   : 2.0
Description : SQL Server Provider

如果您在列表中看不到这些管理单元,请尝试发布 此处.

if you can't see these snap-ins in the list, try the solution posted here.

这篇关于没有为 Windows PowerShell 版本 2 注册管理单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆