Lessons Learned

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

March, 2014

Posts
  • Lessons Learned

    PowerShell for N00bs: Libraries, Paths, and You

    • 0 Comments
    One of the scripts a coworker inherited has the following workflow: 1. Set-Location $PathContainingScript 2. & $Script Why?  Because the original author was a believer in libraries.  Or, specifically, TheMotherOfAllLibraries.ps1.  Divide...
  • Lessons Learned

    PowerShell –EncodedCommand and Round-Trips

    • 0 Comments
    PowerShell.exe accepts the –EncodedCommand parameter, which is a way to ‘wrap’ DOS-unfriendly command strings in such a way as to be safely passed into PSH for execution.  It’s a great feature.  However, it has a huge documentation hole. ...
  • Lessons Learned

    Scripting Best Practices, or Write-Host Considered Harmful

    • 1 Comments
    Disclaimer: this is going to sound like I actually know what I’m doing.  Let’s be honest – I work in Microsoft, home to the people who created PSH, .NET, and the native internals that people invoke with Add-Type and other arcane arts.  There...
  • Lessons Learned

    Hotkeys and RDC Man

    • 0 Comments
    There are days I seem to live on RDC Man.  One day, I might try setting my Shell= to RDCman.exe.  On a VM, of course. At any rate, there are times I need to switch back to the host machine.   While I would like to just see a ‘minimize...
  • 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...
Page 1 of 1 (11 items)