SQL Server Development Bookmark and Share   
 index > SQL Server Tools General > Powershell V2 and SQL Server
 

Powershell V2 and SQL Server

Hello,

I want to replace my current Powershell V1 with Powershell V2 CTP. Is SQL Server 2008 compatible with this replacement and will the new Powershell be successfully recognized?

Regards

George Stanford  Monday, November 10, 2008 12:07 PM
No, the PowerShell provider is a "minishell", which is a delivered closed system. You can, however, load it manually into 2.0: http://blogs.msdn.com/mwories/archive/2008/06/14/SQL2008_5F00_Powershell.aspx

Thanks for participating the forums!

Buck Woody

Program Manager, Microsoft SQL Server

Learn more about SQL Server for Free: http://www.microsoft.com/sql/editions/express/learnvideos.mspx

Great Podcast for SQL Server: http://edge.technet.com/Tags/Database+Administration/feed/ipod

More about me: http://buckwoody.com

BuckWoody  Tuesday, November 11, 2008 12:18 AM
No, the PowerShell provider is a "minishell", which is a delivered closed system. You can, however, load it manually into 2.0: http://blogs.msdn.com/mwories/archive/2008/06/14/SQL2008_5F00_Powershell.aspx

Thanks for participating the forums!

Buck Woody

Program Manager, Microsoft SQL Server

Learn more about SQL Server for Free: http://www.microsoft.com/sql/editions/express/learnvideos.mspx

Great Podcast for SQL Server: http://edge.technet.com/Tags/Database+Administration/feed/ipod

More about me: http://buckwoody.com

BuckWoody  Tuesday, November 11, 2008 12:18 AM

Here is what I found and adapted

Cited from http://blogs.msdn.com/mwories/archive/2008/06/14/SQL2008_5F00_Powershell.aspx

#
# Initialize-SqlpsEnvironment.ps1
#
# Loads the SQL Server provider extensions
#
# Usage: Powershell -NoExit -Command "& '.\Initialize-SqlPsEnvironment.ps1'"
#
# Change log:
# June 14, 2008: Michiel Wories
# Initial Version
# June 17, 2008: Michiel Wories
# Fixed issue with path that did not allow for snapin\provider:: prefix of path
# Fixed issue with provider variables. Provider does not handle case yet
# that these variables do not exist (bug has been filed)

$ErrorActionPreference = "Stop"

# itdoes nothave to be changed to 2, as Buck said this is a mini-delivery

$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

Write-Host -ForegroundColor Yellow 'SQL Server Powershell extensions are loaded.'
Write-Host
Write-Host -ForegroundColor Yellow 'Type "cd SQLSERVER:\" to step into the provider.'
Write-Host
Write-Host -ForegroundColor Yellow 'For more information, type "help SQLServer".'

George Stanford  Tuesday, November 11, 2008 9:04 AM

May I uninstall Powershell 1 before installing Powershell V2? Does it affect SQL Server?

George Stanford  Tuesday, November 11, 2008 8:43 PM

You can use google to search for other answers

Custom Search

More Threads

• Information about microsoft SQL server upgrade
• Remote TSQL Debugger - Not able to set any break points
• Dead Link on Microsoft SQL server 2000 downloads page
• Load Testing tools
• Copy Database Wizard Default Destination Folder
• ODBC SQLSTATE: 42000
• Error 3154: The backup set holds a backup of a database other than the existing 'xx' database.
• Using UniqueIdentifier as Primary key
• Tool For Renaming Table/Column Names
• Catastrophic Error