Over a million developers have joined DZone.

PowerShell Classes for Developers

DZone's Guide to

PowerShell Classes for Developers

From the classic way of creating objects of .NET classes or defining a custom .NET class, we have seen PowerShell extend .NET classes and types in numerous ways.

· DevOps Zone ·
Free Resource

Is the concept of adopting a continuous everything model a daunting task for your fast moving business? Read this whitepaper to break down and understand one of the key pillars of this model in Continuous Governance: The Guardrails for Continuous Everything.

Classes in PowerShell have been a feature since long ago, and creating objects of these classes is nothing new. From the classic way of creating objects of .NET classes (like the MailMessage in Example 1 below) or to defining a custom .NET class (in Example 2 below), we have seen PowerShell extend .NET classes and types in numerous ways.

Example 1: Creating object of a .NET class

$message = New-Object System.Net.Mail.MailMessage

Example 2: Defining .NET class in PowerShell

$source= "
    public class BasicTest 
        public static int Add(int a, int b) 
            return (a + b); 

        public int Multiply(int a, int b) 
            return (a * b); 

Add-Type -TypeDefinition $source

PowerShell Classes

With the new version PowerShell, you can create classes in PowerShell instead of just using .NET classes. Object Orientation is now available in your scripting language so that you can shorten your scripts and make them more maintainable.

I recently spoke about PowerShell Classes at PowerShell Conference Asia, 2015 and it seemed to spark a great deal of interest. So, I created two short videos to help you quickly ramp up your PowerShell skills to create PowerShell classes, objects, methods, overloads, scope, and a lot more. Check out the videos down below.

Video 1: Getting Started With PowerShell Classes

Video 2: Constructor, Methods, Overloading and Scope

Hope this helps you!

Are you looking for greater insight into your software development value stream? Check out this whitepaper: DevOps Performance: The Importance of Measuring Throughput and Stability to see how CloudBees DevOptics can give you the visibility to improve your continuous delivery process.

powershell ,developer ,classes ,object oriented programming

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}