Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

Download “The DevOps Journey - From Waterfall to Continuous Delivery” to learn about the importance of integrating automated testing into the DevOps workflow, brought to you in partnership with Sauce Labs.

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!

Discover how to optimize your DevOps workflows with our cloud-based automated testing infrastructure, brought to you in partnership with Sauce Labs

Topics:
powershell ,developer ,classes ,object oriented programming

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}