Ich versuche ein Powershell-Skript auf einem Webserver auszuführen, auf dem SQL Server Management Studio nicht installiert ist, aber alle relevanten Pakete aus dem Microsoft SQL Server 2008 R2 SP2-Feature Pack wurde installiert. Sie müssen diese kleinen Teile installieren, damit Powershell SQL-Befehle ausführen kann. Server-Befehle ausführen mit PowershellEs wurden keine Snap-Ins für Windows PowerShell Version 2 registriert
Dann dieses Setup-Skript Ich lief die Ihre Umgebung für SQL PREPS:
$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
Bei Add-PSSnapin SqlServerCmdletSnapin100
, schlägt das Skript mit dem folgenden Fehler:
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
lief ich ein Google-Suche nach diesem Fehler und die einzige Lösung, die ich finden konnte, war, dass die Leute mein 64-Bit-Powershell Console-Verknüpfung auf das SysWOW64-Verzeichnis anstelle der System32 verwiesen wurde. Dies ist nicht der Fall für mich. Mine verweist auf System32.
Irgendwelche Ideen? Was muss ich tun, damit Powershell diese Snap-Ins registriert?
Die verknüpfte Lösung war die Antwort. Vielen Dank! – crackedcornjimmy