Skip to main content

Posts

Write-Host – Will the puppies survive

Just updated my virtual computer running Win10. Yes, I am a chicken and have not upgraded my computer from 8.1 yet. Some time in the future I will find time to upgrade, however in the mean time I am quite happy with just running it as a VM. My current build of powershell is 10041 (yes, I know I am falling behind). I was tweeting with Jan Egil (@JanEgilRing). He mentioned a new cmdlet and a couple of new common parameters that has become available in this build. We have two new common parameters: InformationAction InformationVariable Using my previous get all common parameters, we can indeed confirm that these are new common parameters: There is also a new cmdlet called Write-Information which has 2 parameters: [object] MessageData [string[]] Tags There is a new $InformationPreference global variable set to “Continue” by default. In action So here is the first attempt to write something in the console: Write-Information produced no information in...

Getting things done

Attended one of those sessions where the key selling point was “how to get things done”. In other words, get your sh*t together and get organized with zero emails in you inbox. It is a whole philosophy, google it :-) Well one of the suggestions was to use the “send to onenote” program that is installed with OneNote. Of course that is way to may clicks for me and my mouse and I started to look into a quicker way of doing it in powershell, what else? Turns out there are very few posts on the subject, sending things from powershell to OneNote. Found a couple of references using c# and that is almost powershell so of I went and created this function Out-Note. (Out-Note) The function takes two parameters. Note = The text you want to send to OneNote and an optional parameter Section that defaults to “General”. UPDATE - 23 March 2015 Received a tweet from Jan Egil Ring (Powershell MVP - @JanEgilRing ). He was having issues with the function. It would only create a new page ...

Devops – Unit testing in Powershell Part 2

Powershell has really gained a strong momentum the last 3-4 years and is becoming increasingly the scripting language of choice if you live in the Windows part of the IT world. Together with the increasing popularity of the Devops phrase, unit testing is a key factor going forward. This is part 2 ( Part1 ) of a small series of posts related to unit testing in Powershell. You can read the first post her. In the previous post we presented the Scenario we will be working with and the API functions that our SillyModule will wrap logic around. The tasklist Read up on Unit Testing frameworks for powershell (Pester or PSUnit) Create the the SillySystem Import-Object and Export-Object API Walk through of the module and the functions (Get/Update-Person/Group) Create tests for the functions Refactor where needed ad update the tests The SillyModule The context of the module is pretty simple. We need cmdlets to receive a list of persons or groups. The list may be filtered on a s...

Powershell ISE – Increase your productivity

For some time now I have been thinking about extending ISE to increase my productivity. Those of you that do heavy “powershelling” are probably already living inside ISEsteriods which is a terrific and professional extension. For all others this might suit your needs or maybe you will find it lacking in some areas. Why On the top of my head? Why not. Microsoft has created a powerful environment for us which is free and lacking is some areas. Still with the update regime currently being the “defacto” standard there is no way they would satisfy the demanding needs you guys have. Secondly I was kind of curious if it could be done, and last but not least it was fun. Disclaimer Please bear in mind that this is a alpha version 0.1 release and I know there are some issues with it, however it works and demonstrates the capabilities you can implement with very little efforts. I have organized the extension as a module which is built by my build.ps1 script. If you clone the repro a...

Devops – Unit testing in Powershell

Powershell has really gained a strong momentum the last 3-4 years and is becoming increasingly the scripting language of choice if you live in the Windows part of the IT world. Together with the increasing popularity of the Devops phrase, unit testing is a key factor going forward. One of the new phrase/term that is spoken often and warm about is Devops . It represents the evolvement from regular IT operation to IT operations with development. It is getting increasingly difficult to separate what is Operations and what is Development, they are combined into one entity. traditionally IT operations has very limited experience (that is zero) with the unit test concept. Testing is catching on and becoming one of the key elements that separates regulars from professionals in the Devops world. Everyone know they need to learn it and may have done it or are in the process of embracing it. Powershell has really gained a strong momentum the last 3-4 years and is becoming increasingly the...

Powershell Common Parameters - Sometimes they need to go in the bin

This will be a short post. Now and again I find myself needing to know the names of the common parameters that is added to an advanced function. Usually this is because I want to use splatting and want to remove any usage of those built-in parameters. Here is how you can do it. This time I was working on an advanced function that had a lot of parameters, counting in at 34 to be more precise. There was also a nice mixture of default values and calculated values that required my attention. The function should output those parameters with their values like so: -Param1 <value> -Param2 <value> Now I could use $PSboundparameters , however that would not include the parameters with default values, hence I went the other way and used $MyInvocation.MyCommand.Parameters . This will give me a dictionary list of all the parameters including the common parameters (see help about_commonparameters) and those have to be removed. A couple of days ago I was browsing around the [ Sy...

Creating files with powershell

There comes a time when you need to create files with powershell. Search the web and you will find many solutions. Here I am going to list a few of you options. First one up is from the Powershell Magazine by Shay Levy: It is a basic functions with some parameters for you to change the path where the file should be written and the size of the file. Second is from another blog Nate Jones. It is a couple of lines with code for you to run: Third is from Jeffery Hicks. He also use the [IO.File] .Net class to create an advanced function that also supports pipeline input. His function requires Powershell version 4: Click the pictures to find the article about each solution. If you search for your self, you will see pretty much all kinds of variations around the .Net class System.IO.File. Natively in Powershell to my knowledge there is no single cmdlet that lets you create files of an predefined size. So lets dig around and see what we can find. First we need to di...