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