Azure does Powershell too

Azure, PowerShell
Or, I guess it might be more appropriate to say that Powershell does Azure. Regardless, there are a set of commandlets for Azure and Azure SQL Database. Here's the link to get you started and the basic documentation. After that, it's a little tricky to know for sure what's required. Follow the instructions on the link to get the basic set up done, and then I'll show you just a little bit about how you can manage your Windows Azure SQL Database through PowerShell. First up, you need to set up a context, which is basically a connection to your Azure server. This requires very specific objects. The code below outlines what you need: $SQLLogin = new-object System.Management.Automation.PSCredential("UserName", ('12345' | ConvertTo-SecureString -asPlainText -Force)) $context = New-AzureSqlDatabaseServerContext –ServerName 'MyAzureServer' -Credential $SQLLogin…
Read More

HDInsight, Finally

Azure, HDInsight
See this: That's right. The install worked. All I had to do was get a completely clean server set up. No domain controller. Now to get my learn on. Microsoft has a web site with a number of introductory samples. I'll start there and work through them. The very first example gets me set up with some data that it builds by running a Powershell script, importdata.ps1. But I'm not going to just blindly follow along. I want to see what the heck is happening so I can start understanding this stuff. By the way, thank you Microsoft for making the samples in PowerShell and not forcing me to relearn Python or something else. That would have been frustrating. The script is really simple. It has two scenarios you can…
Read More

More Surface

Surface
I’m continuing to work with the Surface. BOOM I just had my first crash. I was in IE when I tried to switch tabs and the pull down window would not stay open. So I tried closing IE. That didn’t work at all. I tried switching to the Start window or switching apps. No joy. I then did a hard restart, holding down the power button for about 10 seconds. On restarting, the system started updating itself, which was weird since I had made sure to do all the updates when I started. The update finished, I logged in, and noticed that the wifi symbol looked funny (wish I had a screen capture, ooh, is there a utility for that?). No big deal until I tried connecting to the wifi…
Read More

SQL University: SQL Azure & PowerShell

Azure, PowerShell
Welcome once more to the Miskatonic branch of SQL University. I see that most off you survived out last encounter… uh, class. Most of you even appear somewhat sane… somewhat. Today we’re going to talk about PowerShell and it’s use with SQL Azure. Which sounds a something like an eldritch horror breaking in from some outer dimension… hmmm… that could explain certain things… So, back to Powershell and SQL Azure. You can’t run Powershell from SQL Azure. Thank you for attending and enjoy your trip home. Still here? I did try. Let’s clarify. You can’t run PowerShell from SQL Azure, but I didn’t say that you couldn’t use SQL Azure as a target for PowerShell. It is possible to connect to your SQL Azure databases running PowerShell from a local…
Read More

Powershell to Automate SQL Compare

Tools
A question came up on the SQL Server Central Forums, how could you use Red Gate SQL Compare to automate creating scripts for all your databases at once. What’s the first thing that popped into my head? Yep, Powershell. SQL Compare Pro comes with a command line utility that allows you to automate just about everything you can do with the GUI. I like to use it when I’m setting up deployment mechanisms for systems because it makes one click deployments possible. I won’t go into all the methods of that type of automation here. For a lot more information on that topic, check out the Team-Based Development book. If you’re interested in exploring how you can use the command line, just type this: sqlcompare/? Now is a good time…
Read More

12 Days of SQL, On the 2nd Day of SQL…

PowerShell
Microsoft gave to me, an excellent new management language. Yeah, so it doesn't rhyme or match the song in any way, but as far as gifts of the season go, PowerShell is it. There are a couple of problems with PowerShell, first, it's not installed everywhere, and second, DBAs just haven't quite latched on to this new language as a management tool. That second problem is absolutely not one that I would say about Aaron Nelson (blog|twitter), our next 12 Days of SQL blogger.  Aaron is one of the leading lights out there educating DBAs, and everyone else for that matter, about the strengths and capabilities of PowerShell as a management language for SQL Server. I've said it twice, and I hope you noticed, but I didn't say scripting language,…
Read More

Powershell Remoting with SQL Server

PowerShell
One of the best things to come out with Powershell V2 is remoting and asynchronous calls. Between the two of these, you can basically send commands simultaneously to a number of SQL Server instances. BUT... and there always seems to be one of those, there is a lot of work required to get this running right. I'm going to outline what I did recently to test the ability of PowerShell to begin administering my servers remotely. Hopefully this provide the basis for a checklist and a how-to. I'll update this post over time so that I get things right. Enable remoting on the machines you wish to call This requires admin privileges, but it's pretty simple unless you need to modify which ports are available, etc. But to get it going the easiest…
Read More

Small PowerShell Script

PowerShell
I'm still trying to learn PowerShell better. The opportunity to answer simple questions and problems with the tool is hard to pass up. We had a need to clean up data directories where data files were left behind or people put inappropiate files, so I wrote the following Powershell script: [sourcecode language="powershell"]param([string]$filelocation="",[string]$sqlinstance="(local)") Set-Location $filelocation foreach($file in get-childitem) {$base = $file.Name; $result = Invoke-Sqlcmd -ServerInstance $sqlinstance -Query "SELECT DB_NAME(mf.database_id) AS db FROM sys.master_files mf WHERE RIGHT(mf.physical_name,LEN('$Base')) = '$Base' UNION ALL SELECT 'NoDb' AS db WHERE NOT EXISTS (SELECT DB_NAME(mf.database_id) AS db FROM sys.master_files mf WHERE RIGHT(mf.physical_name,LEN('$Base')) = '$Base');" ; if($result.DB -eq "NoDb" -and $file.Extension -ne ".cer"){Remove-Item $base}} It's a very simple script. It takes a UNC and a server instance and then walks through the files in the UNC and validates…
Read More

One of these things is not like the other

PowerShell
I'm working with PowerShell, and digging it. I decided that I wanted to create a new script (blog post later, if I get it to work) and I wanted to try out different scripting tools to build it. I started with PrimalScript from Sapien. It's slick. It's powerful. It has very nice code completion, a great GUI, integration with source control out of the box. I started scripting and everything was fine. Then, I needed to run invoke-Sqlcmd so I decided to change the profile on the shell so it would load the SQL Server cmdlets automagically. I started getting the error: Get-ItemProperty : Cannot find path 'HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps' because it does not exist Hmmm... weird. I'm pretty sure I used the same command on my workstation as on my laptop.…
Read More

Learning Powershell

PowerShell
I've been attending a Powershell fundamentals class with Don Jones (blog|twitter). If you read my blog you might be aware of the fact that I've posted a few PowerShell scripts in the past.  So why was I attending a fundamentals class? Because I didn't know what I was doing. I knew going into the class that I needed a better grounding in the fundamentals of Posh, but after the first day of Don's excellent class, I realized that I had been working with PowerShell and didn't have a clue how it really worked. Don's class is excellent and I could spend a lot of time talking about just that (which I'm sure would make Don happy). However I want to concentrate on something that he said during class that really…
Read More