# Lessons Learned

My drop-site for interesting snippets and tips. If it's useful to you as well, great!
Posts
• #### Enums, Enums, Enums, a One-Liner

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...
• #### WMI-Less Network Adapters

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...
• #### Getting Event Logs with wevtutil.exe

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...
• #### One-Liner: Resetting Desktop Toolbar

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...

• #### Prompts

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...
• #### CorpNet ProjectFunctionLibrary.psm1

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...
• #### Getting Disk Usage

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...
• #### Getting an SHA256 Hash

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...
• #### Loop-de-Loop

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? ...