Local user managament Powershell module

I had  task another day to create 30+ local users on two different servers that provide Remote App to external users. Logical path would be to federate with our external users, but  they don’t have AD infrastructure.  We choose (I to be exact) to create local users and to give them access to RDP servers with application they need. I was thinking  “OK, now I create csv file import it, and create users easily with PS cmdlet for creating users!” I was so naive. PoweShell doesn’t have module to work with local users. I don’t know what they are doing in Microsoft but it is so basic. Maybe I didn’t search good enough on Internet  but I found two self made PoweShell modules that help. One is  Local Account Management Module 2.1 that I tried but what ever I do I get this error

image

I gave up. In comments I found out that something is wrong in project and should be changed. It will work on stand alone computers, but if you changed local Account policy it will not work.

I chosen next one Local User Management Module and bingo. This one work. For more help on this module go  to this link1 & link2. How to do it. Save the script like localuser.psm1 file and put in  folder by name for example localusermodule. Then put folder in your personal or default module path. You will find that location like this by power of PS:

 

get-item env:\PSModulepath | fl

You will get next result. Copy folder to any of these folders

image

After that to be certain that you can list module type next command and import module:

get-module -listavailable
import-module localusermodule

image

You will get these cmdlets (lets call it that way Winking smile):

image

Now Create csv file you data and columns names and run this little script for importing multiple users and adding them to local user group for accessing Remote desktop. I hope I helped someone. Microsoft please add Powershell module for local users and groups! If you did please let me now!

Import-Module -Name LocalUserModule

If(!(Test-IsAdministrator)) { "This module requires admin rights." ; exit }

Import-Csv 'C:\Users\superip\Documents\book1.csv' |

Foreach-Object {

  New-localuser -username $_.username -password $_.password -description 'elta kabel korisnik' 

  Set-LocalGroup -userName $_.username -GroupName 'Remote Desktop Users' -add 

}

Remove-Module -Name LocalUserModule