Create Linux users on PowerShell Core 6 with New-LocalLinuxUser

In this article, I will explain my simple function New-LocalLinuxUser for PowerShell Core 6 that acts as a wrapper and allows you to create a local Linux user with PowerShell.

With the general release of PowerShell Core 6.0, users now have the ability to use the previously strictly Windows-based scripting language on Linux and macOS. This is quite a great achievement from the PowerShell team. It not only enables IT pros to manage Windows from other operating systems but also lets them use PowerShell for Linux and macOS IT administration tasks.

Here, I am going to show how you can create Linux users with PowerShell. The idea was to try to port the Windows PowerShell cmdlet New-LocalUser to Linux. Now obviously, Linux creates local users differently than Windows, but the idea is essentially similar.

How does Linux create local users?

Before we write our function, let’s look at the command that creates Linux users: useradd. When comparing useradd with New-LocalUser, I attempted to find similar parameters I could use. Below is a table of these:

New-LocalUser useradd
-Name No named parameter, but you can specify one after useradd
-Description –comment
-AccountExpires –expiredate
-Password –password

 

You could certainly use other parameters with useradd, but I will work with these to make things simple.

An example of using useradd in Linux would be something like this:

Read more at 4sysops.com

Leave a Reply

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