I’m a Microsoft MVP… Again

Sunday, June 30, 2013

It's that time of the year which feels like having a second birthday. I'm proud to announce that I was awarded the MVP title once again. This is my 6th year in a row as a PowerShell MVP, and hopefully not my last! Thank you all, Lechaim!!
14 comments

Skipping empty CSV objects

Tuesday, December 4, 2012

Hi, it’s been a while since my last post, I’ve been busy mostly at work and also by investing most of my time running the PowerShell Magazine website together with my friends. I hope to post more in the future. For the time being, here’s my latest post, cross-posted on the PowerShell Magazine. Working with CSV files in PowerShell is a common practice. You import the file, loop on its records and you’re good to go. Sometimes however you may find yourself in a situation where you get a file that has blank lines in it, and those...
12 comments

Congratulations 2012 Microsoft MVP

Sunday, July 1, 2012

I’ve just received THE email from Microsoft… I’m a PowerShell MVP for another year! I am very honored! This is my 5th renewal and I would like to take this opportunity and say thank you to Microsoft and to all the people who supported me.
9 comments

Creating objects with a cast in PowerShell 3.0

Thursday, April 19, 2012

Starting with PowerShell 3.0, we now have another cool way to create new objects. We can create them by calling the default constructor of the type and initializing its properties with a cast: @{X=1;Y=2} We put the type in square brackets and assign it a hash table containing the properties we want to initialize. Looking at this example got me thinking, how can I know the properties I can set for a specific class/type? As a learning tool, I wrote the Get-HashType function. Give it a type name and it will tell you the properties...
18 comments

How to protect your PowerShell Functions

Tuesday, April 17, 2012

Creating functions in PowerShell is relatively a simple operation. You declare the function’s name and value, press the Enter key and you’re good to go. It is also very simple to override the function just by re-creating it; that’s all it takes, simple and easy. What if you need to prevent that from happening? You don’t want to allow someone or something from overriding your functions? PowerShell gives us the option to do that via a dynamic parameter. Dynamic parameters are cmdlet parameters that are added by a Windows PowerShell provider and are available only when...
one comment

Custom objects default display in PowerShell 3.0

Friday, April 13, 2012

In PowerShell 3.0 we can now create new custom objects using a hash table. PS> @{ One = 1 Two = 2 Three = 3 Four = 4 Five = 5 } One : 1 Two : 2 Three : 3 Four : 4 Five : 5 Behind the scenes, PowerShell creates a hash table and wraps it a PSCustomObject. It is way faster than using the New-Object cmdlet and it also provides consistency, while maintaining backwards compatibility. Another benefit of using...

Add-Member enhancements in PowerShell 3.0

Wednesday, April 11, 2012

PowerShell 3.0 offers new ways to add Note properties to objects. In PowerShell 2.0, a typical command to do that would look like: PS> New-Object -TypeName PSObject | Add-Member -MemberType NoteProperty -Name One -Value 1 -PassThru One --- 1   And when adding multiple note properties: PS> New-Object -TypeName PSObject | Add-Member -MemberType NoteProperty -Name One -Value 1 -PassThru | Add-Member -MemberType NoteProperty -Name Two -Value 2 -PassThru | Add-Member -MemberType NoteProperty -Name Three -Value 3 -PassThru One Two Three --- --- ----- 1 ...
24 comments

Measuring objects in PowerShell 3.0

Monday, April 9, 2012

The Measure-Object cmdlet gives us a great way to find minimum and maximum values in a collection of objects. For example, if we want to know the smallest and largest size of a file in the current directory: PS> Get-ChildItem | Measure-Object -Property Length -Minimum -Maximum Count : 2751 Average : Sum : Maximum : 56297240 Minimum : 35 Property : Length In PowerShell 2.0 it only worked with numeric properties (integers), we couldn't use it to compare properties like LastWriteTime (DateTime). In PowerShell 3.0 we can now use...
one comment

Leveraging Proxy Functions in PowerShell

Friday, March 30, 2012

@DSotnikov just released the video recording of the session from the PowerShell Deep Dive in Frankfurt (last year). In this video, MVP Kirk Munro (poshoholic) and I demoed a project we've been working on that let's you create proxy functions. Here's a reminder of the session abstract. In this session as they take a deep dive into proxy functions in PowerShell. Shay and Kirk have been working together on PowerShell Proxy Extensions, a powerful module that leverages proxy functions and makes it easier than ever to create these powerful extensions to PowerShell. They will demonstrate what proxy functions...

Counting objects in PowerShell 3.0

Monday, March 19, 2012

Consider the following command, how many objects are in $dir? PS> $dir = Get-ChildItem The most common way to find it is to check the Count property: PS> $dir.Count But… the Count property is available only if Get-Something returns more than one object (array/collection), If the result has one object only (scalar) the Count property returns nothing, not even zero. If the result contains more than one object, the objects are accumulated in an Array (collection), and Arrays have a Count property so we get the number of objects. Now back to the question above, how...
one comment