Lessons Learned

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

Posts
  • Lessons Learned

    Configuring the ISE

    • 0 Comments
    I tend to flatten my laptop about once a season. Among the other things I lose is my PowerShell_ISE customizations. They’re not many, but I miss them when I have to live without them. Fortunately, they’re all captured in my Microsoft.PowerShellISE_profile...
  • Lessons Learned

    Left-Padding a String

    • 5 Comments
    I’ll be honest; .NET has more methods and classes and properties than I can shake an idiom at. In my previous blog post, I needed to left-pad a string with zeroes in order to treat it as a 32-bit binary value to [Array]::Reverse() . I also had to do the...
  • Lessons Learned

    Pass the CIDR, Will You?

    • 0 Comments
    Classless Inter-Domain Routing (e.g. 192.168.1.0/24) replaces dotted-notation netmasks (e.g. 192.168.1.0 with a subnet mask of 255.255.255.0) to do the same thing: what IP addresses are considered on-subnet (and therefore do not need to go through the...
  • Lessons Learned

    One-Liner: Left-Padding a String with Zeroes

    • 0 Comments
    Yesterday’s post had a little bit of sleight-of-hand involved.  For the IPv4 address to UInt64 conversion to work, each octet had to be converted into an 8-character string of ones and zeroes.  However, [convert]::ToString($int, 2) doesn’t zero...
  • Lessons Learned

    IPv4 Addresses and CIDR Fun

    • 0 Comments
    Classless Inter-Domain Routing is the current way to define a subnet.  An example entry would be “192.168.1.0/24”.  What this means is that the first 24 bits of the 32 bit IPv4 address are considered ‘off the subnet.’  The last octet is...
  • Lessons Learned

    PowerShell ISE Environment Keyboard Shortcuts, Part 2

    • 2 Comments
    A coworker asked how many of these shortcuts I knew. Given that I had to go looking for a shortcut that was explicitly displayed in the Edit menu, I guess you know the answer. Then, he said he wished he could learn them. That gave me an idea… ...
  • Lessons Learned

    PowerShell ISE Environment Keyboard Shortcuts

    • 0 Comments
    It started with a simple question: is there a shortcut to go to the Console Pane in the ISE?  A few web pages gave lists of shortcuts, but then this guy went the extra … parsec. http://www.powershellmagazine.com/2013/01/29/the-complete-list-of-powershell...
  • Lessons Learned

    $PSModuleAutoLoadingPreference and You

    • 0 Comments
    This is a very simple onelner.  The problem statement is a more complicated. PSH 3 and 4 treat PSModules in a very funny way.  These versions have a default module path, and will return any cmdlet that happens to be in any module that happens...
  • Lessons Learned

    Filtering Show-NetIPSec Rules based on IP Address

    • 0 Comments
    Get-NetIPSecRule seems a little half-baked.  A coworker asked me to come up with a way to only return IPsec rules for a given address.  I’m surprised Show-NetIPSecRule natively doesn’t have that, nor does each record have the RemoteAddress property...
  • Lessons Learned

    Getting Trusted Domain Computer Names

    • 0 Comments
    The -replace '\..*', $domain snippet is in case here's some AD funkiness that returns the FQDN from the external DNS record instead of internal. Some of my labs expose machines to other labs. Dammit, Jim, I'm a lab admin, not the DNS guru. function Get...
  • 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.     #>  ...
Page 1 of 9 (222 items) 12345»