Category: Blog

  • Powershell in a Month – Day 2, Help

    This is part of my Powershell Challenge, to learn more about Powerhsell (PoSh) using the Learn Windows Powershell 3 in a Month of Lunches book by Don Jones.

    Today was Chapter 3, Using the Help System. Another not-so-exciting topic, but one that does matter. There are a ton of commands to learn and use in PoSh and being able to get help on them is important if you are to develop code with any level of speed. Note I said code. This is scripting, it’s interactive, but it’s code. Whether you run it once or save it and schedule executions every minute, it’s code.

    The first point in the chapter is to RTFM, or “read the friendly manual”. The authors emphasize that using Google instead of help means you’re copying code, not learning about the code, and potentially stunting your development or even wrecking your production system with commands you don’t understand. As much as I love Google, I can understand the point here.

    One of the first things the chapter does is ask you to update help. However that didn’t work for me:

    Posh_006

    The book doesn’t talk about the CLI v the ISE, which is the problem. I found a post on MSDN that noted this works from Powershell, but not the Powershell ISE.  Once I went to the CLI, it worked.

    Posh_005

    I used to do UNIX work, and was forever typing “Man xxx” to learn about xxx. MAN is a wrapper here, as is “help” for the get-help command. I played around with some get-help stuff, using wildcards and tab completion. Both of which are handy. I can definitely see that learning to use help and tab is important.

    The rest of the chapter brings out various ways in which you can use help, including getting more details, getting examples, and going to the online pages, which are more up to date than your local copy might be. All good tricks to getting going with PoSh. Lots of example commands showing how to get help, and I ran most of these.

    The chapter was boring, but at the end when I got to the lab, I was surprised how little I know. As I tried to go through the lab questions, I wasn’t sure what was working and what wasn’t. I didn’t know if I was actually running the right commands, since things like “help *array*” worked. There are answers you can download from the morelunches.com site, and once I did that, I was able to check my results, and get help on a few items I wasn’t sure about. 

    I was surprised that I learned a few things, and I can definitely see that working with help is both important, and cumbersome. For example, the scrolling isn’t smooth in the ISE and the MORE piping from the HELP wrapper doesn’t work. Definitely something to practice on as I move through the book.

  • Powershell in a month – Day 1

    I got started on Learn Windows Powershell 3 in a Month of Lunches at lunch one day. Working at home makes this easy as I have a computer and a kitchen near each other. In this case, a salad, a bowl of chili, and the laptop next to the book to get started. The picture below was post-chili.

    20131106_114540

    This is the first post in my Powershell challenge. I don’t expect to post every day as I travel, have vacation, etc, but I will post once for each of the days I work on this. At the end, I hope to have a couple PoSh presentations I’ll build as well as more incorporation of PoSh into my talks.

    Day 1

    I cheated slightly today. I read the first and second chapters here. The first was really a “how to use this book” and the second actually got me started. The first introduces what Powershell is, why it’s good, etc. It’s a good intro, but I’ve been through most of this before, I know something about the environment, and I’ve used it a bit for specific tasks. If you are new to PoSh, read this.

    I didn’t get much out of it, so I went into Chapter 2, despite the warning from the book not to do more than one a day. Instead, practice. I made an exception this first day.

    The second chapter gets you familiar with how to set up your environment. As it mentioned, PoSh gives you two ways to work with it on most modern OSes. The command line or the Integrated Scripting Environment (ISE). I tend to use the ISE, but you can choose. In this case, I popped both open. One note here, I’m on Win 8 and if I hit the Windows key and type “power”, I see this:

    Posh_001

     

    There’s no ISE available. This is different on different machines for me. However if I finish “Powershell” and add a space “i”, I get the ISE. Not a bid deal, but an interesting item for me.

    Posh_002

    The second chapter really goes into getting the environment set up first. Choose large fonts, which is a must for older folks like me. I definitely plan to make this a part of any presentations I do. The chapter also emphasizes that typing matters and accuracy is important. PoSh is case sensitive and different separators, like the various grouping items, matter. These:

    ([{<

    are all different and you can’t mix and match them. Make sure you know the difference. It’s especially try for the single quote (‘) and the backtick (`). Learn the difference.

    No scrolling was another important point since you can lose things on the screen. For me, I set the font to 18, left the default colors, and then in the ISE, removed the command window and script editor. That left me full screen with the interactive shell.

    Posh_003

     

    From there, I played a bit with the way PoSh works. Typing part of commands, and then using Tab or Shift+Tab to cycle through commands. Using these keys to get folders, or parameters, or choices, was handy.

    Nothing really executed today, but I did play with various commands to see what happened. The one thing I did run was

    Get-Service SQLAGENT

    I typed Get-s, hit tab to cycle through choices, and then entered “SQ” and tab’ed to get SQLAgent. That gave me the status of the service on my laptop.

    Posh_004

     

    That was the basic  learning for today. It’s simple, and a little boring, but it is stuff to know that will make future days easier and build some familiarity with the environments.

    Tomorrow, chapter 3.

     

  • T-SQL Tuesday #48–Cloud Atlas

    tsqltuesdayI never saw the movie, though it’s on my list to watch sometime. I love the Wachowski’s as directors.

    This month Jorge Segarra is hosting. He is better known as the SQLChicken, and his theme this month is Cloud Atlas. He’s asking us to write about the cloud and what we think of it. What’s our take on the cloud. He wants to know if we’ve used it, what we think, probably how we even define it. It’s a great question with all the media and hype about the cloud, especially for data professionals.

    This is a monthly blog party, where bloggers write on a specific topic every month, on the second Tuesday. I’ve got a complete list of topics on this blog, and to participate, do this:

    • write a blog
    • publish it on the Tuesday, November 12, 2013 (for this month)
    • be sure a trackback or comment is on Jorge’s blog invitation
    • include the T-SQL Tuesday logo, linked to the invitation.

    That’s it. Write, and enjoy.

    The Cloud Atlas

    What is the cloud? It’s been hyped in commercials and numerous articles, and to some extent I think we don’t have a good definition. We have PaaS, IaaS, and SaaS, all of which are legitimately the “cloud” for different people.

    As far as I’m concerned, the cloud really is any computing service that is provided by a vendor. This means you don’t own the hardware and rent out either a machine (physical or virtual), a service, a set of APIs, etc. This exclude co-location, but anything else from renting a VM to using IFTTT, is cloud computing.

    With that in mind, what do I think? There are certainly problems with the cloud in terms of security and recovery of data. However I think the promise of renting out computing resources (machines/platform/software/services) in a scalable fashion is amazing to me.

    Do I use the cloud? Sure. I have Evernote, Skydrive and Dropbox to keep my data in sync. My family uses OurGroceries to manage a shopping list. We daughter is hooked on Spotify, which alleviates the need to keep much music on her device. I even have backups of data on Glacier.

    On the career side, we (SQLServerCentral and Red Gate) offer AdventureWorks on Azure for users to play with. I’ve done minor work in Azure, and spun up a SQL instance on AWS. I haven’t actually done anything more than test, personally, but certainly the cloud is useful for SQLServerCentral. We host our database server and web server on virtual machines we rent from Rackspace. We use a Content Delivery Network for some videos and YouTube for others. We’ve dramatically lowered costs and increased scale with the cloud.

    The cloud works.

    Sometimes.

    For some applications.

  • How SQL Server Full Backups Work

    I’m writing this in support of a few talks I give that talk about backups. This is how I see things and it’s based on things I’ve learned over time. Some of this comes from a great explanation on Technet from Paul Randal, but there are misc other sources that I can’t be sure of which ones I’ve used. Long story short: I learned most of this from others and docs. It’s not all me.

    There are two parts to a full backup in SQL Server:

    • data reading
    • log writing

    Technically both sections read and write, but this is how I think of things. I’ll describe there:

    Data reading – The backup process goes through all extents allocated and reads a page, sends it to a buffer and that gets written to the backup file. This happens as fast as SQL can do it, just going through the pages, but it takes most of the backup time.

    Log writing – all of the log records that are written while the data reading portion of the backup is running are appended to the backup file, after the data pages.

    Let’s say that the entire time of the backup, from the File Created to the File Last Modified timestamps on the backup file is represented by t. The data reading portion of the backup takes time d. The log writing portion of the backup takes time l.

    This gives us:

    t = d + l

    My database is transactionally consistent at backup start time + d, not + t. When is that? I’m not sure, but usually it’s fairly close to the timestamp at the and of t.

    Make sure that your backups are transactionally consistent. Don’t export, don’t use open file managers, don’t use anything that doesn’t respect transactions. The native SQL Server backup process does this. If you want a few other features, my employer makes SQL Backup Pro, which also respects transactions.