Return Multiple Values from PowerShell Function

In PowerShell functions, by default, you can return only one object at a time. Since PowerShell does not apply any restriction on data type returned, it created a lot of possibilities on what can be returned as an output of the function. So if one needs to return multiple values or objects, it is generally suggested to create an array of the objects and then return the array. If the underlying values are simple strings, some would create a custom PSObject and then return the PSObject. In this blog post, we will discuss the other methods to return the multiple values from PowerShell functions.
Continue reading “Return Multiple Values from PowerShell Function”

Write Advanced functions in PowerShell using various Write Cmdlets

PowerShell has become de-facto tool of choice for automation in Microsoft world from long time and slowly it is winning over hearts of the Linux administrators as well. Just like with other programming languages, there are many ways to do the same thing in PowerShell. However they differ in little subtle ways. You may or may not notice them in your day to day usage, but if you learn those subtleties, you can quickly improve the performance and results of your automation. This blog post is about one of the such cases only.
Continue reading “Write Advanced functions in PowerShell using various Write Cmdlets”

Running PowerShell Core in a docker container

PowerShell core is the edition of PowerShell built on top of .NET Core. It is sometimes simplified to “CoreCLR”, though it technically includes CoreFX as well.

PowerShell Core is cross-platform, available on Windows, macOS, and Linux, thanks to the cross-platform nature of .NET Core. On PowerShell Core, $PSVersionTable.PSEdition is set to Core.

Do note that  while PowerShell Core 6.0 is cross-platform, there is also a PowerShell Core 5.0/5.1 released exclusively as part of Nano Server. In this blog post, we’ll learn how to run PowerShell core in a docker container. Continue reading “Running PowerShell Core in a docker container”

Install PowerShell Core on Ubuntu / CentOS using package management

Microsoft has release latest bits of PowerShell core and published PowerShell Core 6.0 alpha.15 to https://packages.microsoft.com. So we can use package management tools like yum or apt-get to install the latest PowerShell version on Linux distributions. It’s as simple as registering the Microsoft repository once as superuser and then just need to use either sudo apt-get install powershell or sudo yum update powershell (depending on which distribution you are using) to update it …Continue Reading