Hello @M, RAKESH ,
Thank you for reaching out to Microsoft Q&A platform.
1.For Windows, you could achieve this with the below PowerShell Script. This will automate this process. It will create a new user, add them to the "Users" group, set a temporary password of "P@ssword1", then set that password to be expired so the user will change their password when they log in. You can add the users you want to be created by adding them to the $users variable and following the example formatting.
# The default password for the new accounts
$password = ConvertTo-SecureString "P@ssword1" -AsPlainText -Force
# Group new users are added to (default is Users)
$group = "Users"
# PowerShell array containing the users to be created
$users = @(
# List users here to be created
"user1"
"user2"
"user3"
)
# Creates a new users for each entry in the $users array
foreach ($user in $users) {
# Create and add user to Users group
New-LocalUser -Name "$user" -Password $Password
Add-LocalGroupMember -Group "$group" -Member "$user"
# Set users password to be changed at next logon
$expUser = [ADSI]"WinNT://localhost/$user,user"
$expUser.passwordExpired = 1
$expUser.setinfo()
}
now, to run this across VMs in one go, you could further leverage PS command "Invoke-Command"
PowerShell allows you to run local PS1 scripts on remote computers. The idea is that you store the PowerShell script above in a local .PS1 file on your computer. With PowerShell Remoting, you can transfer a PS1 file to a remote computer and execute it there.
To do this, use the -FilePath parameter in the Invoke-Command cmdlet instead of -ScriptBlock. For example, to run the c:\ps\usercreationscript.ps1 script on three remote servers, you can use the following command:
Invoke-Command -FilePath c:\ps\usercreationscript.ps1 -ComputerName server1,server2,server3
For more details, refer to run-powershell-script-on-remote-computer
- For the Linux, you can check the following link create-multiple-users-using-shell-script-in-linux
Disclaimer: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as convenient to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
Please "Accept as Answer" if any of above helped so that, it can help others in community looking for remediation for the similar issues.