Richard

  • Home
All Posts Links About

Richard

  • Home

PowerShell Scripts to check SQL Database servers

2008-07-16

I have four production database servers to manage. They are all SQL 2005 Server. Sometimes I need to know the name, owner, size, available space of all the DBs on each server. I create this little PowerShell scripts to do that instead of opening up all the servers in SQL Server Management Studio.

[reflection.assembly]::LoadWithPartialName(“Microsoft.SqlServer.Smo”) | out-null
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$computers = get-content “DBServers.txt”
$OutFile = “DBServerInfo.txt”
$Line = “Production Databases information”
$Line | out-file $OutFile
foreach ($computer in $computers)
{
$Line = “rn———————————–”
$Line | out-file $OutFile -append
$Line = “Working on “ + $computer
write-host $Line
$Server = new-object (“Microsoft.SqlServer.Management.Smo.Server”) “$computer”
$Line = “Server :” + $computer + “ (Version: “ + $Server.Information.VersionString + “)rn———————————–”
$Line | Out-File $OutFile -append

$Server.databases | select name,owner,@{Name=”Size(MB)”;Expression={“{0,8:0.00}” -f $.size}},`
@{Name=”Available Space(MB)”;Expression={“{0,8:0.00}” -f ($
.SpaceAvailable/1024)}}`
| Format-Table -auto | Out-File $OutFile -append
}

write-host “Output File Created: .” $OutFile
  • PowerShell

扫一扫,分享到微信

微信分享二维码
PowerShell Script to Check SQL Server Error Log
WMI Classes links
© 2017 Richard
Hexo Theme Yilia by Litten
  • All Posts
  • Links
  • About

tag:

  • ASPNET
  • DotNetCore
  • VS2015
  • Service Pack 2
  • SQL Server
  • Database Restore
  • SQL Server 2008 R2
  • GitHub
  • Blog
  • Trace Flags
  • SQL Server 2017
  • Linux
  • SQL Server Management Studio
  • SSMS
  • SQL Server 2014

    缺失模块。
    1、请确保node版本大于6.2
    2、在博客根目录(注意不是yilia根目录)执行以下命令:
    npm i hexo-generator-json-content --save

    3、在根目录_config.yml里添加配置:

      jsonContent:
        meta: false
        pages: false
        posts:
          title: true
          date: true
          path: true
          text: false
          raw: false
          content: false
          slug: false
          updated: false
          comments: false
          link: false
          permalink: false
          excerpt: false
          categories: false
          tags: true
    

  • SQL Server Updates
  • SQLBlog.com
  • SQL Server Central
  • My Old Blog Site 1
  • My Old Blog Site 2
  • Unicode Character Map for Windows
  • Dev Tool List (From Scott Hanselman)
Improve daily life using IT techs.