Databases Reference
In-Depth Information
$sqlservice = Get-WmiObject -namespace root\Microsoft\SqlServer\ComputerManagement10
-class SqlService -filter "DisplayName = 'SQL Server ($instanceName)'"
# If the SQL Server instance has been installed successfully
if ($sqlservice)
{
# Standalone instance
if ($template.SQLINSTALLTYPE -eq "STANDALONE") {
# Get rid of unnecessary double quotes
$sqlNetworkName = $template.HOSTNAME.Replace("`"", "")
# Set TCP port as specified in the template file
"Setting TCP port to " + $tcpport + " ..."
# Disable dynamic ports
$dynamicPorts = Get-WmiObject -namespace root\Microsoft\SqlServer\
ComputerManagement10 -class ServerNetworkProtocolProperty `
-filter "PropertyName = 'TcpDynamicPorts' and IPAddressName = 'IPAll'
and InstanceName = '$instanceName'"
$dynamicPorts.SetStringValue("") | Out-Null
# Set static port
$staticPort = Get-WmiObject -namespace root\Microsoft\SqlServer\
ComputerManagement10 -class ServerNetworkProtocolProperty `
-filter "PropertyName = 'TcpPort' and
IPAddressName = 'IPAll' and InstanceName = '$instanceName'"
$staticPort.SetStringValue($tcpport) | Out-Null
# Restart server for the new port number to take effect ...
$sqlservice.StopService() | Out-Null
$sqlservice.StartService() | Out-Null
"Waiting for the SQL Server service to be completely recovered ..."
Start-Sleep 60
# Execute Upsert-Server to insert the new instance into the inventory
"Adding new instance to the inventory ..."
Invoke-Sqlcmd -Query "exec sp_configure 'show advanced options', 1;
RECONFIGURE" `
-ServerInstance "$sqlNetworkName,$tcpport" -Database master
[String] $upsertString = "C:\DBAScripts\Upsert-Server -instanceName "
+ $instanceName `
+ " -hostName " + $sqlNetworkName + " -status " + $template.STATUS
$upsertString + "`n"
Invoke-Expression $upsertString
}
#Failover cluster instance
elseif ($template.SQLINSTALLTYPE -eq "CLUSTER") {
# Get rid of unnecessary double quotes
$sqlNetworkName = $template.FAILOVERCLUSTERNETWORKNAME
.Replace("`"", "")
Search WWH ::




Custom Search