Posted on October 27, 2010, 8:03 pm, by Rhys, under
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 [...]
Posted on February 21, 2010, 7:51 pm, by Rhys, under
Powershell.
I’m looking at building some Powershell scripts that can accept user input to perform different tasks with a wizard style interface. As it happens this is fairly easily achieved with the Read-Host cmdlet. Here’s a quick script showing how such a powershell script may look. ?View Code POWERSHELLfunction mainMenu() { Clear-Host; Write-Host "============"; Write-Host "= [...]
Posted on February 9, 2010, 10:24 pm, by Rhys, under
DBA,
Powershell.
Here’s a Powershell script that can be used to manage index fragmentation in SQL Server databases. The strategy I’ve used in the script is based on a recommendation from Pinal Dave (blog | twitter) in his article Difference Between Index Rebuild and Index Reorganize Explained with T-SQL Script. Just set the $sqlserver and $database variables [...]
Posted on February 1, 2010, 11:56 am, by Rhys, under
Powershell.
Here’s a Powershell snippet that randomly sorts the lines in a file. The snippet below reads a text file, called file.txt, located in your user profile directory. The data in the file will be written back with the lines in a different order. ?View Code POWERSHELL$data = New-Object System.Object; $data = Get-Content "$Env:USERPROFILE\file.txt"; # Random [...]
Posted on January 16, 2010, 4:50 pm, by Rhys, under
Powershell.
One of the great things about Powershell is its ability to take advantage of the .Net platform. If Powershell can’t do it you bet there’s a .Net library that can. Not only is this great for extending your scripts but I also like to use Powershell to test some of my classes. Rather than fire [...]
Posted on December 28, 2009, 3:26 pm, by Rhys, under
Powershell.
Chuck Boyce Jr (blog | twitter) recently commented on a limitation of the script from my post Discover SQL Servers with Powershell. The script does require that the SQLBrowser service is running for discovery to occur which may be a major issue for some. Here’s an alternative method that does not have this limitation. All [...]
Posted on October 28, 2009, 9:34 pm, by Rhys, under
Powershell.
Powershell is a pretty cool tool for many things including working with data. It’s just such a great time saver if you have to deal with multiple files or need to change them into different formats. Here’s how easy it is to turn a csv file into well-formed xml. ?View Code POWERSHELL# csv file to [...]
Posted on October 1, 2009, 8:14 pm, by Rhys, under
Powershell.
A few days ago I was working with a client that was providing an export of data from Oracle. The file being produced was choking my SSIS package due to various formatting issues. After working with the client and getting a file that looked good to the naked eye I discovered that a large amount [...]
Posted on September 23, 2009, 10:59 pm, by Rhys, under
Powershell.
I’ve blogged before about the usefulness of Powershell for data tasks. A few weeks ago I had a requirement at work for merging csv files and recently I needed to split a single csv file into several files. While this is easy to do using SSIS and a bit of T-SQL it is a little [...]
Posted on September 15, 2009, 9:14 pm, by Rhys, under
Powershell.
Progress bars can be a nice visual indicator as to how a far a task is into its workload. Windows Powershell provides us with the ability to create these within the console fairly easily. This simple code will demonstrate the basics of the Write-Progress cmdlet, which allows us to deploy progress bars in our scripts. [...]