Lessons Learned

My drop-site for interesting snippets and tips. If it's useful to you as well, great!

Posts
  • Lessons Learned

    Importing Azure RDC Files into RDCMan.exe’s RDG

    • 0 Comments
    This is really over-engineering.  Azure’s “connect” link sends you a .rdc file to download or open.  The registered handler for .rdc files is mstsc.exe, a.k.a. Remote Desktop Connection. The key line in the .rdc file is “Full Address:s:FQDN...
  • Lessons Learned

    Namespaces, Why Does It Always Have To Be Namespaces?

    • 0 Comments
    I’ll be honest, I LOATHE namespaces in XML.  I haven’t seen a case where I needed to use them to differentiate between identically-named elements in different contexts.  So often, the document declares a namespace at the top and never overrides...
  • Lessons Learned

    Backing Up BitLocker Recover Key (Strikes Again!)

    • 0 Comments
    Here’s a one-liner for backing up the BitLocker Recovery Key for every drive attached to the machine: ZgB1AG4AYwB0AGkAbwBuACAAQgBhAGMAawB1AHAALQBCAGkAdABMAG8AYwBrAGUAcgBSAGUAYw… Followed by 9kb of more of the same.  It’s an EncodedCommand, so we...
  • Lessons Learned

    BitLocker and Voice

    • 0 Comments
    I loathe BitLocker.  In fact, I often let a ‘ch’ phoneme slip in between the first and second vowel.  The reason is that it seems to be on some random hair-trigger.  Patching will trigger Recovery Mode.  Sometimes even having a USB...
  • Lessons Learned

    SkyDrive, OneDrive, Let’s Call the Whole Thing Off

    • 0 Comments
    (Apologies to Istanbul (Not Constantinople) by Jimmy Kennedy and Nat Simon.) We all know about SkyDrive being renamed OneDrive.  However, I don’t see a way to determine which is where on what machine.  Rather than dive through the registry for...
  • Lessons Learned

    $PSBoundParameters and CommonParameters (-WhatIf, -Debug, etc.)

    • 0 Comments
    For the longest time, I was unable to get $PSBoundParameters to work to detect –Debug , -Verbose , etc. CommonParameters. Here’s a handy page that captures the output of about_CommonParameters . http://technet.microsoft.com/en-us/library/hh847884.aspx...
  • Lessons Learned

    I Hate Write-Host So Much…

    • 0 Comments
    Write-Host is evil. It’s just plain evil. In fact, it’s so evil that I learned to make a proxy function for it. What’s a proxy function? Glad you asked. I’m basing my work on this post by Shay Levy. http://blogs.technet.com/b/heyscriptingguy/archive/2011...
  • Lessons Learned

    YOMER Yet One More Error Reporting (Method)

    • 0 Comments
    I wrote about creating an Out-Error function before to avoid outputting the stack dump that a normal Write-Error displays.  Many newcomers to PSH take one look at the huge blob of angry red text and throw up their hands in frustration. Write-Error...
  • Lessons Learned

    Subshells (by the Seashore?)

    • 0 Comments
    Yesterday’s post detailed some frustration I encountered running PowerShell in a subshell.  Why was I running it in a subshell in the first place? I’m glad you asked. It all started a long time ago (well, a few years, but it felt like a long time...
  • Lessons Learned

    Send-Keys

    • 0 Comments
    Firstly, I am standing on the shoulders of giants.  As the comments below state, the essential first function, Set-WindowState, is only slightly modified from the original form at http://www.snip2code.com/Snippet/50118/Hide--Show--Minimize--Maximize...
  • Lessons Learned

    Decrypting SecureStrings (Once More!)

    • 0 Comments
    [PSCredentials] have some interesting methods. Chief among them, at least for today, is GetNetworkCredential() . Well, what’s so special about this? The returned object has the .Password property which is the plaintext of the password. I’ll say it again...
  • Lessons Learned

    One-Liner: PowerShell Tools for Visual Studio 2013

    • 0 Comments
    Unsure if I posted this already, and sorry if I did. http://visualstudiogallery.msdn.microsoft.com/c9eb3ba8-0c59-4944-9a62-6eee37294597 Adam Driscoll posted Visual Studio extension that allows it to edit PSH. It’s not as feature-rich (IMPO) as PowerShell...
  • Lessons Learned

    Starting Elevated PowerShell Windows

    • 0 Comments
    There are a few commands I have to run from Elevated PowerShell windows (such as suspending Bitlocker prior to patching).  It’s not that hard to right-click on my pinned-to-taskbar PowerShell icon and select “Run as Administrator”, but I wanted to...
  • Lessons Learned

    Creating Local Users

    • 0 Comments
    I’m helping some of our test teams more and more.  In one case, we need to create local users in bulk. I’m surprised PSH doesn’t have something for this.  function New-LocalUser { <# .syopsis Creates a local user account .parameter...
  • Lessons Learned

    Querying WMI with a Timeout

    • 0 Comments
    This is thanks to my coworker Keith Munson, who is at least as passionate and adept at PSH as I am:   function Get-WmiObjectWithTimeout {     <#     Credit to Keith Munson for this.     #>  ...
  • Lessons Learned

    Storing SecureStrings Machine-Independently

    • 0 Comments
    As part of a brown bag, I extracted out the logic CredLocker uses to store credentials.  Here’s the guts of the code. The short form is unchanged from the Credlocker post, but I’ve cleaned it up. - It prompts the user for a password if $Host.CredentialStoreCredential...
  • Lessons Learned

    Comparing Performance Counters

    • 0 Comments
    A common TSG step is to look at some perf counter, wait n minutes, then look at it again. When we’re talking about pools, it gets a little more involved.  PerfMon.exe isn’t the most easy to automate (you can save the counterset to an .msc, then copy...
  • Lessons Learned

    One-Liner: Symlinks and Windows

    • 0 Comments
    Windows 7 and above support symbolic links, but the OS needs to be updated to recognize them: fsutil behavior set SymlinkEvaluation R2R:1
  • Lessons Learned

    One-Liner: Fun with Multi-line Blocktext and –Split/.Split()

    • 0 Comments
    The title is an oxymoron: I’m going to show a one-liner on how to deal with multi-line blocktext.  To start with, I’m using ‘blocktext’ to mean: $blocktext = @" This is an example using @" .. "@ "@; which is known...
  • Lessons Learned

    Getting SRV Records with PowerShell

    • 0 Comments
    PowerShell leverages .NET, and .NET exposes the System.Net.Dns class, so all should be happy, no?  Evidently not if it comes to SRV records.  Someone asked me how to do it, and I said, “That’s easy.  I’ll get back to you in a few.” A few...
  • Lessons Learned

    One-Liner: Valid PSH Verbs

    • 0 Comments
    I try to use proper PowerShell verbs, but I’m not always sure what they are (or what they do, which is another matter).  Here’s a quick one-liner to dump those verbs out as a [string[]]$array: Get-Command -CommandType cmdlet | Select-Object -ExpandProperty...
  • Lessons Learned

    MSSQL Server Error Logs

    • 0 Comments
    MSSQL Server error logs exist in the same folder that contains the installed server bits.  They’re text files.  Easy-as-pie to read, right? No. MSSQL is often installed on a dedicated drive.  You can’t assume it will be in C:\Program Files...
  • Lessons Learned

    One-Liner: Padding a Number with Leading Zeroes

    • 0 Comments
    I’m putting this here only because I’m tired of searching for it.  How to pad an integer with leading zeroes is trivial.  1..16 | % { "{0:D2}" -f $_ } And padding a float with trailing zeroes is more of the same: $i = 2; (1..10) |...
  • Lessons Learned

    Yet Another Password Generator

    • 0 Comments
    This must be freshman programming again.  I’m redoing CredLocker and want the way to parametrically generate passwords with minimum character set counts. This is also a good example of New-Object System.Random and [char[]]”Casting a string to char...
  • Lessons Learned

    Reinventing the Wheel: Get-WmiChildNamespace and Get-WmiChildPropertyData

    • 0 Comments
    I love and hate WMI.  I love how it offers the ability to access so many parts of the OS that PowerShell has not (yet) exposed via cmdlet.  I hate how the taxonomy is so deep, how you need to know what you’re looking for to find it. Also, I...
Page 1 of 9 (212 items) 12345»