17 April 2017

How do I - Remove an item from a Powershell array.

Because Powershell is so close in syntax to C#, we often forget that it is in fact, NOT C#.  A good example of this is manipulating arrays.  While Powershell did implement the += method for adding items to an array, it does not support -= for removing them.  Fortunately, the -ne switch serves the same purpose.  See the following example for a quick demonstration of removing items from an array in Powershell.

$list = @(); #Initialize the array.
$list += "Apple"; #$list = "Apple"
$list += "Orange"; #$list = "Apple", "Orange"
$list += "Tomato"; #$list = "Apple", "Orange", "Tomato"
$list += "Grape"; #$list = "Apple", "Orange", "Tomato", "Grape"
$list -= "Tomato"; # ERROR!!! You can't do this!
#but this works
$list = $list -ne "Tomato"; #$list = "Apple", "Orange", "Grape"

Enjoy
C

SharePoint Remote Event Receivers are DEAD!!!

 Well, the time has finally come.  It was evident when Microsoft started pushing everyone to WebHooks, but this FAQ and related announcement...