jaredpar's WebLog

Code, rants and ramblings of a programmer.

Browse by Tags

Tagged Content List
  • Blog Post: Easier script deployment in PowerShell 2.0

    If you can’t tell from reading entries in my blog I’m a bit of a script junkie.  I loathe typing out the same command sequence more than once.  As such I go to great lengths to script as much as possible in life.  I also enjoy sharing my scripts with other members of my team. Unfortunately...
  • Blog Post: Test-ItemProperty utility function

    I was playing around in the registry the other day and found the PowerShell API lacking in a key area.  There does not appear to be a good way to detect the presence of a Registry Name/Value pair.  All of the operations such as New, Delete, Rename are based off of the program knowing the presence...
  • Blog Post: Simulating Closures in PowerShell

    Previously I blogged about PowerShell’s lack of closure support within a script block.  This presents a significant hurdle in developing a LINQ like DSL for powershell which I’ve been working on.  Imagine the following syntax $a = from it in $source where {$it -gt 5 } This would be the...
  • Blog Post: PowerShell LINQ: Take-Count and Take-While

    The Take pair of functions are very similar to the Skip functions .  The Take expression does essentially the opposite of the Skip functions.  Skip is useful for getting elements further down the pipeline.  Take is used for getting elements from the start of the pipeline.  #=====...
  • Blog Post: PowerShell LINQ: Skip-While

    Next up in the PowerShell LINQ series is SkipWhile .  This LINQ function takes an enumerable instance and a predicate.  The function will skip the elements in the enumerable while the predicate is true.  The argument to the predicate is the current value of the enumerable.  The LINQ...
  • Blog Post: LINQ like functions for PowerShell: Skip-Count

    The PowerShell pipeline, is fairly similar to C#/VB’s LINQ.  Both filter a group of elements through a series of transformations which produce a new series of elements.  The devil is in the details of course but I’ll get to that in a future post.  When using PowerShell I constantly find...
  • Blog Post: Script Blocks and Closures (or lack there of)

    Script blocks are a concise way of representing an expression or statement group in Powershell.  It’s the C#/F#/VB lambda equivalent for PowerShell.  One difference between C#/F#/VB lambda expressions and a scriptblock is the lack of lexical closures (otherwise known as variable capturing)...
  • Blog Post: Script Blocks and Arguments: Figuring it out for myself … again

    Script blocks are a powershell construct for storing an expression or group of statements inside an expression.  It’s the equivalent of a C#/F#/VB Lamba expression.  Recently I needed to use a script block but found I had forgotten how to read passed parameters inside the script block. ...
  • Blog Post: Count-Object

    With all of the great built-in commands for processing pipelines the absence of a good command to count the number of elements in a pipeline seems to stand out.  The best built-in way to count the number of objects in a pipeline is to convert the value into an array and then take the length. For...
  • Blog Post: Sorting out Binary Files

    I constantly get tripped up in my powershell scripts/commands because I run them against a binary file.  In particular when I’m searching through a directory structure looking for a particular string or regex.  I’ve found the simplest way to avoid this problem is to use a simple regex check...
  • Blog Post: Stop the Beeping!!!

    Recently I was working on a PowerShell script which involved translating byte arrays into strings using the appropriate encoding.  Unfortunately I kept getting the wrong choice for encoding and printed out essentially random data to the console screen.  Unfortunately random data + windows console...
  • Blog Post: Program Files, I just want the 32 bit version

    As part of my transition into using 64 bit windows I keep running into a problem with some scripts.  I have a whole set of Powershell scripts that are dedicated to ensuring certain programs are installed on all of my dev machines.  Or that certain customizations are needed.  A lot of these...
  • Blog Post: Powershell and 64 bit windows helper functions

    Recently at work I started using Windows 2008 64 bit edition.  Mainly for hyper-v but powershell also comes as part of the deal.  I'm starting to work through the fun issues of getting some of my environment specific scripts to run in a 64 bit powershell process.  The following scripts...
  • Blog Post: Using PowerShell to make sure your XP machine is defragmented

    Quick script you can run at login to ensure that your XP machine is being defragmented. I chose 1:00 AM every evening but you can quickly alter that in the script. I have this script run as part of my regular set of configuration scripts to ensure that my XP machines are in good shape. $script:title...
  • Blog Post: Is there anything in that pipeline?

    One operation I frequently perform is use a powershell pipeline to filter out a large set of data. Typically I don't care what is in the result but rather is there actually anything left in the pipeline. I can't find a good powershell built-in to perform this task so I use the following filter. function...
  • Blog Post: Saved by PowerShell

    Recently I made a very large update to our code base.  Our code base lacked a standard way of guarding entry and exit points into the various components.  Having said guards is useful for error handling, tracing, reducing redundancy, etc ...  The edit standardized our entry points by adding...
  • Blog Post: Get-TfStatus

    Been far too long since I blogged about a new PowerShell script. This is not to say I've stopped using PowerShell, more that I've been too busy playing with other tools to spend a significant amount of time updating my scripts. This is a simple, yet straight forward script. The intent is to make the...
  • Blog Post: Get-Content and File Names

    Another day, another PowerShell feature discovered.  Unfortunately this time it was a feature that made me think I had a bug in my script.  The script read through some directories, did some file parsing and created a data object for every directory in the form of a Tuple .  One of the...
  • Blog Post: Tuples Part 8: Finishing up

    There are only a few missing features from our tuple implementation.  Mainly FxCop compliance, debugging support and test case code.  The actual functional work is complete.  The one issue with FxCop compliance is the chosen names.  Namely using A,B etc.  FxCop, rightly, believes...
  • Blog Post: A smarter Select-StringRecurse

    Previously I blogged about a recursive select-string function. Recently I've extended it a bit. I found the function to be very useful but when I encountered problems searching large directories that contained binary files. Namely searching them usually returned a result of sorts and printing out the...
  • Blog Post: Tuples Part 4: Interface

    Now we have a decent tuple generation script which produces a very usable set of tuple classes. After awhile I ended up getting stuck because the tuples are not flexible enough. It's not possible to use a 2 pair tuple where a 1 pair is expected even though it meets the requirements. Process( Tuple .Create...
  • Blog Post: Tuples Part 3: Type Inference Friendly Constructor

    Last time we were left with a constructor that required us to explicitly specify generic parameters. This is not always easy or possible. We'll now alter the script to generate a constructor which utilizes type inference to create a Tuple. In addition, all tuples will use the same overloaded method making...
  • Blog Post: Tuples Part 1

    A tuple in computer science can be described as a set of name/value pairs. In some cases it can be described as simply a set of values that are accessible via an index [1]. Previously I discussed how to create a Tuple inside of PowerShell . This series will focus on the use of Tuples in DotNet and how...
  • Blog Post: Ternary: Reducing code

    I like my scripts to be readable and terse. They're scripts after all and I want to get the most done with the least amount of code. There's a lot to be said for having a readable script but I only value that when I intend to keep the script around for awhile. PowerShell does not have a ternary operator...
  • Blog Post: Filtering get-psdrive to all Local Drives

    Recently I needed to filter the return of get-psdrive to return all of my local hard drives. I didn't want to accidentally start operating on floppies, CDROM's and more importantly, network drives. There are a couple of ways to do this but I found the most straight forward is to combine the WMI data...
Page 1 of 2 (39 items) 12