Lessons Learned

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

Browse by Tags

Tagged Content List
  • Blog Post: PowerShell for Non-N00bs: System Uptime Via WMI

    Getting the last time a system was rebooting is pretty easy from WMI. From this half-decade old post , we get the two key bits: the LastBootUptTimem property of the Win32_OperatingSystem WMI class. In PowerShell, it looks like this: PSH> (Get-WmiObject -Query 'SELECT LastBootUpTime FROM Win32_OperatingSystem...
  • Blog Post: PowerShell One-Liner: What's the Function Name?

    Rather than have to put the function's name in the error mesage (and then forgetting to change it when I copy/paste/rename/modify it), here's a quick function that I can embed in the error message to spit out the function's name: function Get-FunctionName { ( Get-Variable MyInvocation -Scope 1).Value...
  • Blog Post: PowerShell One-Liner: Hardware SKU

    Someone asked me what kind of server I was running in the lab. Uh, I don't have lab access, and even if I do, how the heck would I find it? PS> Get-WmiObject Win32_ComputerSystem | fl Domain : testlab Manufacturer : HP Model : ProLiant DL380 G4 Name : testlab1234 PrimaryOwnerName : TotalPhysicalMemory...
  • Blog Post: PowerShell One-Liner: Strings to Arrays and Back Again

    I'm (just) a old-school Perl hacker and miss their join() and split() functions. Turns out, while PowerShell doesn't have them, .NET does, to a point. PS> $home.split("\") C: Users timid And the other way around. PS> [String]::Join("|", $(gci)) Contacts|Desktop|Documents|Downloads|Favorites...
  • Blog Post: PowerShell One-Liner: Stripping Comments and Blanks

    I know, I know, XML is the new standard. There are still times where flat files are easier. Time is short, and I'm lazy. (I'm also impatient and working on hurbis. Geek-points if you can tell me where that's from.) Anyhow, here's a quick-and-dirty way to strip out comments, whitespace and blank lines...
  • Blog Post: PowerShell One-Liner: Decrypt-SecureString

    Let's say you have a $secureString. If you don't have one handy, create one: PSH> $secureString = ConvertTo-SecureString -Force -AsPlainText "hello" Actually, we're breaking the system - SecureStrings aren't supposed to be created this way - they're supposed to be created like this: PSH>...
  • Blog Post: PowerShell for Non-N00bs: Symlinks

    Here's how to create a shortcut in PowerShell. Actually, it's how to create a shortcut with COM in PowerShell function New-ShortCut { param ( [ string ] $target = $null , [ string ] $name = $target , [ string ] $parent = ( Get-Location ).ToString(), Normal 0 ...
  • Blog Post: Tech Tips: Command Prompt++ - the console.exe tool

    Much of this blog deals with PowerShell, which is primarily command-line. PowerShell.exe is built on top of cmd.exe, and inherits the strengths (if you call block selecting a strength) and weaknesses from its progenitor. Yes, PowerShell has an ISE, but its inability to politely handle terminal control...
  • Blog Post: PowerShell for N00bs 4: More Properties than a Monopoly Board

    We used Select-Object -Property to, well, select properties (after all, PowerShell is trying to move away from obscure abbreviations and truncated names.) How do we know what properties exist? Get-Member . We covered this in N00bs 2. Get-Member gets the ... class members of a PowerShell object...
  • Blog Post: PowerShell One-Liner: Is this a debug build or not?

    In a dev environment, there are debug builds and there are retail builds. And there are debug builds that get mistaken for retail builds... Here's a quick way to see if the binary in question is a debug build or not: PSH> (Get-Command kernel32.dll).FileVersionInfo.IsDebug False Good. I'm...
  • Blog Post: PowerShell One-Liner: sort | uniq -c

    Another track, this time for me to collect useful scripting snippets. Here's one: In Unix, if I have a non-unique list of strings, it's sometimes interesting to see the frequency in which the particular strings appear. For example, I have a list of errors from a long, and need the top 10. In Unix, it...
  • Blog Post: PowerShell for Non-N00bs: My Script Outline

    This is more for me to know where to go looking for this. I don't expect anyone else to laud it and worship it. If you find it useful, great. If you find holes in it, please let me know. At the end of this post will be a walkthrough. #region #######################################################################...
  • Blog Post: PowerShell for N00bs 3: What's a.k.a. short for?

    "Also known as." It's an abbreviation, a TLA. (What's a TLA short for? "Three Letter Acronymn." See: recursion, definition.) In PowerShell for N00bs 2 , we snuck something in the last example: PSH> (gm -InputObject [string] | where-Object {$_.name -eq 'replace'}).definition System.String...
  • Blog Post: PowerShell for N00bs 2: Power Under the Hood

    "Hello, World!" That's how you write "Hello, World" in PowerShell. No, this isn't a flashback to PowerShell for N00bs 1 . Back then, we skimmed over some interesting concepts. Specifically: PowerShell is Object Oriented. "Hello, World" (and every object) has a ToString() method. Object...
  • Blog Post: PowerShell for Non-N00bs: How Much is That Character in the Window? (Or, How to Change Your Password Without Really Trying)

    I'm creating a slightly different track here. PowerShell for Non-N00bs is for me to track some of the tidbits I've found along the way. This will be a two-fer article. By this I mean I'm going to address two tangentially related subjects: how to find an 'odd' character that is visible, but not matching...
  • Blog Post: PowerShell for N00bs 1: Hello, World

    "Hello, World!" That's how you write "Hello, World" in PowerShell. Give it a try: PSH> "Hello, World" "Hello, World!" PowerShell has some very unorthodox behaviours, such as "To execute a string, print it." (There's more to it than simply "print it," but that's for later.) Actually, if it...
  • Blog Post: PowerShell for N00bs 0: References

    (I actually wrote this blog after PowerShell for N00bs 1: Hello, World , but the content of this entry I wrote before the blog entry.) Many PowerShell texts are available. I have only read a few, and offer the following opinions: Microsoft Windows PowerShell Step by Step – Very good first book...
Page 1 of 1 (17 items)