Loading SQL Server Assembly into Powershell

The below script will get the log information of sql server named instance from power shell command.


clear
#Loading sql server SMO Assembly
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SQLServer.SMO")
$SQLServer="RAMESH\DEV"
$MySQL=New-Object ("Microsoft.SQLServer.Management.Smo.Server")$SQLServer
$MySQL.ReadErrorLog()|
Select-Object LogDate,ProcessInfo,Text,HasErrors -First 10|
Format-Table -AutoSize


#Getting information of multiple sql server instances.

Import-Module sqlps 
clear
#Loading SQL Server assembly into Powershell
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SQLServer.SMO")
#The below names are sql server named instances
$servername=@("RAMESH\DEV","RAMESH\TEST")
$servername|
Foreach-Object {
$computername=$_
$Getinfo=New-Object("Microsoft.SQLServer.Management.Smo.Server")$computername
$Getinfo.Databases|Format-Table
#Select-Object DomainInstanceName,BackupDirectory,IsClustered,State,AvailabilityGroups,URN,ClusterQuorumType,Databases|
#Format-Table
}

Comments

Popular posts from this blog

System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

Pre login Handshake or Connection Timeout Period

Transparent Data Encryption(TDE) with Master Key and Certificate in SQL Server