Now that PowerShell is available on various Linux distributions (such as CentOS, Red Hat, and Ubuntu), it is natural for Windows sysadmins to begin tinkering on Linux machines. One of the first thoughts I had after hearing the news that PowerShell was cross-platform was “I wonder what I can script with PowerShell on Linux?” The answer to this question is: quite a lot! In this article I will show you two very simple PowerShell scripts you can use on CentOS.

PowerShell Core does not have the fancy cmdlets Windows users are familiar with, such as manipulating the firewall, services, or storage since these are native only to Windows. In fact, at the time of this article there are only 352 commands in PowerShell Core as Get-Command shows.

So how can we use PowerShell to create scripts on Linux like we are used to on Windows? We have to use native Linux commands like crontab, df, and systemctl that perform tasks for which PowerShell does not have cmdlets. Since PowerShell is just another shell on Linux, it can run these Linux commands within PowerShell.

Adding a PowerShell module in Linux

While you can create PowerShell functions in a .ps1 file on Linux and run them within the console, I prefer to create modules. Currently, PowerShell Core on CentOS has three directories in which to store modules:

While you can create PowerShell functions in a .ps1 file on Linux and run them within the console, I prefer to create modules. Currently, PowerShell Core on CentOS has three directories in which to store modules:

Read more at 4sysops.com

Categories: Technical

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Technical

Restart multiple computers with the PowerShell PCSVDevice module

To restart multiple computers with PowerShell and without relying on functionality of the remote operating system, you can use the PCSVDevice module. The module contains several useful cmdlets for out-of-band management and supports the IPMI Read more…

Technical

Remotely migrate user data with USMT and PowerShell

USMT has been a staple for system administrators for years and has greatly reduced the time to migrate data between computers. USMT has the ability to migrate user files, OS settings, and application settings. It Read more…

Technical

Deploy VMware VMs with PowerCLI and MDT

If you are managing Windows servers, chances are you have a mix of physical and virtual servers in your data center. While VMware provides a method to create VMs from templates to simplify server deployments, Read more…