Lessons Learned

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

Posts
  • Lessons Learned

    Enums, Enums, Enums, a One-Liner

    • 0 Comments
    Enums are short for Enumerations, which is a fancy way of saying, “map this [string] to that [int].”  They’re handy when you want to limit choices, such as ‘Continue’, ‘SilentlyContinue’, etc. In this case, I’m looking at the System.Net.NetworkInformation...
  • Lessons Learned

    WMI-Less Network Adapters

    • 0 Comments
    We can get a list of network adapters (calling them NICs is a bit outdated: the C in NIC stands for ‘card’, like it’s something you plug into an ISA or PCI slot.  These days, it’s almost always built in) from Get-WMI Win32_NetworkAdapter and Win32_NetworkAdapterConfiguration...
  • Lessons Learned

    Getting Event Logs with wevtutil.exe

    • 0 Comments
    A long time ago, I wrote a painful way to export event logs (to CSV) on Server 2003, which lacks wevtutil.exe. Well, here’s the flip side of the coin. Also, I wrote a simple wrapper to get the topmost event log names. It’s really just Get...
  • Lessons Learned

    One-Liner: Resetting Desktop Toolbar

    • 0 Comments
    For some reason, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams\Desktop is set on some of these machines, which means my previous snippet to set it in http://blogs.msdn.com/b/timid/archive/2014/02/19/meatball-surgery-the...
  • Lessons Learned

    Those Who Don’t Know Their History…

    • 1 Comments
    My function:\prompt changes every so often. For my latest, see http://blogs.msdn.com/b/timid/archive/2014/02/07/prompts.aspx ... but one thing I have often used is the snippet ($([int]((Get-History | Select-Object -Last 1).ID) + 1)) This gives...
  • Lessons Learned

    I Should Have Done This Years Ago (New-Shortcut, Revisited)

    • 0 Comments
    In spite of having this blog, sometimes I rewrite a function because I forgot I wrote it already.  Case in point, New-Shortcut.  It was one of my earlier entries in this blog: http://blogs.msdn.com/b/timid/archive/2009/09/06/powershell-for-non...
  • Lessons Learned

    Meatball Surgery, the Taskbar, Toolbars, and You

    • 2 Comments
    It takes me a while, but when I get used to something, I hate to change.  Windows 7 introduced the new Taskbar, and I hate it.  I hate having to click or hover over a ‘stack’ PSH windows to select one. I prefer the old XP (rest in peace) way...
  • Lessons Learned

    The Clipboard

    • 0 Comments
    Talk about a sea change. I started off wondering how to read text out of the clipboard. Thanks to this link below, that’s trivial, and it even showed me a better way than | clip.exe to stuff it into the clipboard. My exact words: “Well, that...
  • Lessons Learned

    I Never MetaCharacter (I Didn’t Like)

    • 1 Comments
    Lame title jokes aside, a metacharacter is a character that describes other characters. Put together, they form Regular Expressions. Regular expressions are used for string matching, which is a less threatening way of saying parsing . Basically, with...
  • Lessons Learned

    Finding Disk Hogs (i.e. Large Folders)

    • 0 Comments
    “Disk full? It was only at 60% last week! Where did all the space go?” If you haven’t said this, then you probably won’t appreciate this post. It seems such a relatively simple task – give me a list of the biggest folders...
  • Lessons Learned

    Sanity-Checking RDG Files

    • 1 Comments
    Remote Desktop Connection Manager is a must-have tool. However, it too easily falls out of date. Depending on your environment, you might be spinning up new machines regularly, especially if you’re in a virtualized environment. Here’s a quick...
  • Lessons Learned

    Modules vs. Scripts: It’s Not Just the Letter ‘M’

    • 0 Comments
    Here’s an interesting gotcha if you are spawning a new window for asynchronous execution via the "cmd.exe /c start" hack. This works as expected in a script, but doesn’t work in a module. $start = get-date cmd /c start powershell -command "start...
  • Lessons Learned

    Stupid Profile Trick: $PROFILE as Module

    • 0 Comments
    I’m spending a lot of time on my $PROFILE for some reason.  Don’t tell my boss. :) Anyhow, we know that Get-Module will get you a list of modules, and Get-ChildItem Function:\ | Select-Object –Property Name, Module will show you what functions you...
  • Lessons Learned

    Prompts

    • 0 Comments
    What does your function:\prompt look like? Here’s mine: function prompt { if ($Host.IsAdministrator -eq $null) { $CurrentUser = [Security.Principal.WindowsIdentity]::GetCurrent(); $CurrentUserPrincipal = New-Object Security.Principal...
  • Lessons Learned

    CorpNet ProjectFunctionLibrary.psm1

    • 0 Comments
    Sorry, nothing really intranet related here. Instead, I have a few lines of code from my CorpNet ProjectFunctionLibrary.psm1 that I want to share for managing this system. Update-ProfileSystemProfile: The goal for this system is to have the same code...
  • Lessons Learned

    $PROFILE and RDP Sessions

    • 0 Comments
    Let's start with the design discussion first. Problem Statement: I need to RDP onto multiple machines in multiple labs for multiple projects. Each project has its own customizations to my $PROFILE. I need a way to keep all those files up-to-date and...
  • Lessons Learned

    Getting Disk Usage

    • 0 Comments
    No time to document it.  Had to throw something together, so here it is. function Get-DiskUsage { param ( [Parameter(ValueFromPipeline=$true)][string[]]$Path = (Get-Location).Path, [string]$CsvPath = "$env:TEMP\$($MyInvocation.MyCommand...
  • Lessons Learned

    Getting an SHA256 Hash

    • 0 Comments
    To steal from the .DESCRIPTION section of the comment-based help: “Yes, PowerShell3 has Get-FileHash, but I have some PSH V2 environments that don't benefit from that yummy goodness.” function Get-Sha256Hash { <# .SYNOPSIS...
  • Lessons Learned

    Loop-de-Loop

    • 0 Comments
    Here’s a quick trivia question for you: Given the following two looping constructs: foreach ($item in $array) { Do-Something -With $i; } and for ($i = 0; $i -lt $array.Count; $i++) { Do-Something -With $i; } What's the difference? ...
  • Lessons Learned

    Read-Host With a Timeout, Kind Of…

    • 0 Comments
    Let’s copy the stuff from the comment block first: This is an unholy union of $ost.UI.RawUI.ReadKey() and Read-Host. It is usable, but that's good enough for my current needs. Let's let the .DESCRIPTION speak for itself: Here are the limitations...
  • Lessons Learned

    Testing Timestamps of Files Across a Slow Network

    • 0 Comments
    I’m not sure if this is because of network lag, or the fact that my lab is on a different AD domain (and different NTP clock) than my local computer.  All I know is: (Get-Item local\path\to\OriginalFile.txt).LastWriteTime –eq (Get-Item remote\path...
  • Lessons Learned

    Getting Version Data From Comment Based Help

    • 0 Comments
    Disclaimer: There’s a lot of parse-by-prayer here. You Have Been Warned. Here’s the short form: I try to keep a change log of sorts in the comment-based help for my scripts. (I say try because that’s sadly the first thing to be omitted...
  • Lessons Learned

    One-Liner(s): X509 Certificate Store Names and You

    • 1 Comments

    All right, we know that we can access a remote computer's various X509Certificate stores via .NET, and 'My' corresponds to "Local Computer\Personal\Certificates". What are the other names?

    ...
  • Lessons Learned

    One-Liner: Case-Insensitive XML Queries

    • 0 Comments
    I'm a one-trick pony with XML. I use $xml.SelectNodes("//name[@attribute='value']") and permutations thereof. However, XML's SelectNodes() and SelectSingleNode() methods are case-sensitive. My coworker Keith Munson found this tidbit: $xml.SelectNodes...
  • Lessons Learned

    Regular Expressions, Search-and-Replace Interpolation and Delegates

    • 0 Comments

    How to search-and-evaluate: find something, modify it via a function, then replace what was found.

    ...
Page 3 of 9 (213 items) 12345»