Updated new-user.ps1

This commit is contained in:
Markus Fleschutz 2023-12-05 09:00:27 +01:00
parent 7d34c7cdf5
commit 587c0824b9

View File

@ -2,29 +2,30 @@
.SYNOPSIS
Creates a new user account
.DESCRIPTION
This PowerShell script creates a new user account.
This PowerShell script creates a new user account with an encrypted home directory.
.EXAMPLE
PS> ./new-user.ps1
PS> ./new-user.ps1 Joe
Created new user 'Joe' with encrypted home directory in 11 sec
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$Username = "")
param([string]$username = "")
try {
if ($Username -eq "") { $Username = Read-Host "Enter new user name" }
$StopWatch = [system.diagnostics.stopwatch]::startNew()
if ($username -eq "") { $username = Read-Host "Enter the new user name" }
$stopWatch = [system.diagnostics.stopwatch]::startNew()
if ($IsLinux) {
& sudo adduser --encrypt-home $Username
& sudo adduser --encrypt-home $username
} else {
throw "Not supported yet"
}
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ created new user '$Username' with encrypted home directory in $Elapsed sec"
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
"✔️ Created new user '$username' with encrypted home directory in $elapsed sec"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"