Lessons Learned

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

Posts
  • Lessons Learned

    Do-Something | Set-Variable Foo

    • 0 Comments
    Especially for stuff that generates a lot of output, I’ve learned to pipe commands to Set-Variable. It’s no different than starting the command with “$foo =”, such as $foo = Do-Something, However, I like ‘building’...
  • Lessons Learned

    Function Skeleton for Invoke-Command –AsJob

    • 1 Comments
    PSRemoting jobs are quite amazing. While they are a little complicated to grasp at first, they’re quite powerful. However, with great power usually comes great responsibility. We know we can spawn a gazillion jobs, but how about managing them? How...
  • Lessons Learned

    Parsing Dates by Hand

    • 0 Comments
    I’m always impressed by the amount of variety in input formats that Get-Date can accept and still parse it into a date. However, there is one time that it vexes me: US vs. EU date strings.  Specifically, the US uses dd/MM/[yy]yy, while the EU uses...
  • Lessons Learned

    CredLocker – Storing PSCredentials to File

    • 0 Comments
    Summary CredLocker is tool to securely store PSCredentials to a file such that the file can be copied to multiple hosts and the PSCredentials can be retrieved from that file via processes running on those hosts. The function + the data store file...
  • Lessons Learned

    Invoke-WebRequest, a First Attempt

    • 0 Comments
    “To learn PowerShell, you first have to have a problem to solve.” Well, this is utterly non-work-related, but I’m sure I can find more respectable uses than defeating the idleout of a web chat. The situation is pretty simple: I’m on a fandom site where...
  • Lessons Learned

    Capturing Write-Noun Cmdlet Output

    • 0 Comments
    I’m sure there’s a cleaner way to capture the output from Write-Host, Write-Verbose, etc.  However, I’m just going to “go caveman” in the words of a coworker and just hack around with the Verb-Transcript cmdlets. Without further ado: function Get...
  • Lessons Learned

    One-Liner: Getting My Documents and Other Special Folders

    • 0 Comments
    I have roaming profiles, which is great until I need to reference stuff in my Documents folder. Sure, I can hardcode \\ProfilerServer10\Mydocs2\timdunn\My Documents into my script, but I want to make my scripts more reusable by my team members. The closest...
  • Lessons Learned

    WMI and HP Product IDs

    • 0 Comments
    An HP Product ID is related to the hardware SKU The plain-English way of getting the SKU is Get-WMIObject –ComputerName $computerName Win32_ComputerSystem However, our inventory system uses the HP product ID property stuffed in ILO.  As someone who...
  • 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...
Page 2 of 8 (196 items) 12345»