Posts Tagged ‘Powershell’

Powershell Primary Key & Clustered Index Check

It’s considered a bad practice  Not using Primary Keys and Clustered Indexes here’s a Powershell script that can make checking a database for this very easy. Just set the $server to the sql instance you want to check and $database as appropriate. ?View Code POWERSHELL# variables $server = "sqlinstance"; $database = "badDB"; # Load SMO [...]

The Poor Mans data compare with Powershell

Each new cmdlet I discover makes me fall in love with Powershell a little bit more. A while ago I discovered the Compare-Object cmdlet. The examples given in the documentation demonstrate how to compare computer processes and text files but I was interested to see if this would work with a dataset. So I tried [...]

Getting the size of files created in a date range

I was recently asked for a list providing size details of all the database and transaction log backups we take for SQL Server. Along with this I was asked to provide the approximate daily backup size. Since I’m no fan of trawling through folders, ordering by date modified, and then viewing properties to get the [...]

Powershell Keyboard Shortcuts

Here’s a few of the keyboard shortcuts for Powershell I always find myself using during the day at work. Pause output on the screen Sometimes a command may produce lots of output causing the screen to scroll rapidly. Pressing Control & S will pause the output currently on the screen. Press any key to continue [...]

Can you send that to me in an email?

Sometimes I’m writing Powershell scripts to gather information on a seemingly ad-hoc basis and then someone says; "Oh, and can you send that to me in an email every day|week|month". These scripts would often use a bunch of Write-Host statements to output to the console. Modifying these to send the output in an email can [...]

Guest Post on Scripting Guys

I’ve written a post about Documenting Databases with Powershell that’s featured today on the Microsoft Scripting Guys blog. Head on over and check it out!

Performance benchmarking with Powershell

I’ve been working on a performance benchmarking project recently to gauge the effect of new releases to our systems. Powershell happens to be very useful gathering various system statistics using the Get-Counter cmdlet. There’s literally a tonne of available counters for everything to disk use, memory usage to sql server specific counters. You can list [...]

Send email with Powershell

There’s two methods I often use for sending email in my Powershell scripts. The first uses the Send-MailMessage cmdlet and the second resorts to using the .Net Framework. Why do I use two methods? Well…. ?View Code POWERSHELLSend-MailMessage -To ‘me@here.com’ -From ‘sender@here.com’ -Subject ‘Test Message’ -Body ‘This is a test message.’ -SmtpServer ‘smtp.server.com’; The Send-MailMessage [...]

Powershell… Making it difficult for yourself!

Today I was reading the post Powershell is Really Easy… If you know what you’re doing and it really struck a chord with me. A few days ago I discovered the ConvertTo-HTML cmdlet that can easily convert Powershell objects into formatted html pages. As I’ve written a few scripts producing html output, by sticking together [...]

Gathering SQL Server Data Cache Information: Part 2

In a previous post I showed how you can collect information on what is held in the data cache. The data collected here was just a simple summary of how much space each database was consuming. While useful we will need more detailed information on what is inside the cache to get a proper handle [...]