2012-11-09 169 views
11

SQL Server Management StudioがインストールされていないWebサーバーでPowershellスクリプトを実行しようとしていますが、Microsoft SQL Server 2008 R2 SP2 Feature Packの関連パッケージインストールされています。 PowershellがSQLコマンドを実行できるようにするには、小さなビットとピースをインストールする必要があります。 Add-PSSnapin SqlServerCmdletSnapin100Windows PowerShellバージョン2にスナップインが登録されていません

$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 

、スクリプトは次のエラーで失敗します:

は、それから私は、SQL ServerのコマンドがPowerShellを使用し実行するための環境をプレップこのセットアップスクリプト実行

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 ConsoleのショートカットがSystem32ではなくSysWOW64ディレクトリを指していると言っているということでした。これは私には当てはまりません。私はSystem32を指しています。

アイデア? Powershellにこれらのスナップインを登録させるには何が必要ですか?

答えて

7

あなたが行う場合は、次のことができます場合

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 

Get-PSSnapin -Registered 

あなたは(ここではSQLのためだけのもの)はPowerShell用のすぐに使用できるスナップインのリストを取得しますリストにこれらのスナップインが表示されていない場合は、hereというソリューションを試してみてください。

+1

リンクされた解決策が答えでした。ありがとうございました! – crackedcornjimmy

3

上記の回答と少し似ていますが、私はデフォルトで、32ビットで動作するVisual Studioコマンドプロンプトを使用していたことがわかりました。

したがって、私のPowerShellライブラリに対して「InstallUtil」を使用すると、32ビットバージョンのPowershellに登録が行われたので、-Registeredコレクションに自分のコマンドレットが見つからないことがわかりました。

私がその後powershell(x86)を起動した場合、私のスナップショットは実際に期待どおりに登録されました。そこで、私の解決策は、x64コマンドプロンプトからスナップショットを再登録するか、単純にx86版のpowershellを使用することでした。

0

Windows Server 2008 R2 PowerShell修正プログラムは、問題のあったサーバーにPowerShellレジストリキーをコピーすることでした。

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\ 

問題を解決しました。 SharePoint PowerShellスナップインが登録され、SharePointがインストールされます。

関連する問題