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.
#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