Sto tentando di eseguire uno script PowerShell su un server Web in cui SQL Server Management Studio non è installato ma tutti i pacchetti pertinenti dal pacchetto Microsoft SQL Server 2008 R2 SP2 hanno stato installato È necessario installare questi piccoli frammenti affinché Powershell sia in grado di eseguire comandi SQL.Nessun snap-in è stato registrato per Windows PowerShell versione 2
Poi ho eseguito questo script di installazione che prepara l'ambiente di per SQL comandi Server eseguiti con 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
Al Add-PSSnapin SqlServerCmdletSnapin100
, lo script non riesce con il seguente errore:
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
ho fatto un La ricerca di Google su questo errore e l'unica soluzione che ho trovato è che la gente diceva che il mio collegamento a console PowerShell a 64 bit era indirizzato alla directory SysWOW64 anziché a System32. Questo non è il mio caso. Il mio punta a System32.
Qualche idea? Cosa devo fare per ottenere da Powershell la registrazione di tali snap-in?
La soluzione collegata era la risposta. Grazie! – crackedcornjimmy