Skip to main content

Posts

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...

Operations Manager–Gateway servers and failover with Powershell dynamic parameters

Been thinking about doing a post about failover in SCOM with gateway servers. The idea is that you have several (2 or more) SCOM management servers in your management group. As you start to build your first gateway server, the question about failover/high availability for the gateway comes walking down the street. No problem, powershell comes to the rescue and provides you with a cmdlet you can use – Set-SCOMparentManagementServer . All nice and dandy, however you can only set the primary management server or the failover server, not both at the same time. In addition you have to provide the cmdlet with gateway and management server objects. You cannot just specify their names. These are by no means huge issues, however I wanted to play around with the dynamic parameter in Powershell and decided to get to work. Just a fair warning. Dynamic parameters are not pretty in Powershell, however if you put a little effort into the logic, it is quite reasonable to understand. What do...

PowerBus–Sending and receiving ServiceBus messages from powershell

I have been working on implementing ServiceBus using powershell. There is to my knowledge no modules/scripts available to communicate with ServiceBus from powershell. There is a Azure powershell module on Git that enables you to create/manage Queues/namespaces, however not to send/receive messages. Let’s just jump right in and test it. Requrements: Create a Queue on Azure and recceive the connection Information (connectionstring) ( http://azure.microsoft.com/en-us/documentation/articles/service-bus-dotnet-how-to-use-queues/ ) Download/clone the PowerBus repository on bitbucket ( https://bitbucket.org/torgro/powerbus/wiki/Home ) Unblock the downloaded zip file (unblock-file –path c:\temp\PowerBus.zip) Copy the module to one of your module paths Import-Module –Name PowerBus How to use After importing these commands will be available for you: Get-BusMessage and Send-BusMessage are used for receiving and sending messages to the Queue. These functions need to...

Powershell - Get loaded assemblies

Sometimes you need to check if an assembly is loaded in your session. How can you check if an assembly is loaded in your current session? You can use this function I have created or roll you own command using [System.AppDomain] and the static method GetAssemblies(). Code: Cheers Tore