2023-10-31 12:48:22 +01:00
|
|
|
|
<#
|
2022-01-31 14:24:06 +01:00
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Creates a new user account
|
|
|
|
|
.DESCRIPTION
|
2023-12-05 09:00:27 +01:00
|
|
|
|
This PowerShell script creates a new user account with an encrypted home directory.
|
2022-01-31 14:24:06 +01:00
|
|
|
|
.EXAMPLE
|
2023-12-05 09:00:27 +01:00
|
|
|
|
PS> ./new-user.ps1 Joe
|
2024-04-28 16:35:16 +02:00
|
|
|
|
✔️ Created new user 'Joe' with encrypted home directory in 11s.
|
2022-01-31 14:24:06 +01:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
2022-09-06 21:42:04 +02:00
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2022-01-31 14:24:06 +01:00
|
|
|
|
#>
|
|
|
|
|
|
2023-12-05 09:00:27 +01:00
|
|
|
|
param([string]$username = "")
|
2022-01-31 14:24:06 +01:00
|
|
|
|
|
|
|
|
|
try {
|
2023-12-05 09:00:27 +01:00
|
|
|
|
if ($username -eq "") { $username = Read-Host "Enter the new user name" }
|
|
|
|
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
2022-01-31 14:24:06 +01:00
|
|
|
|
|
|
|
|
|
if ($IsLinux) {
|
2023-12-05 09:00:27 +01:00
|
|
|
|
& sudo adduser --encrypt-home $username
|
2022-01-31 14:24:06 +01:00
|
|
|
|
} else {
|
|
|
|
|
throw "Not supported yet"
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-05 09:00:27 +01:00
|
|
|
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
2024-04-28 16:35:16 +02:00
|
|
|
|
"✔️ Created new user '$username' with encrypted home directory in $($elapsed)s."
|
2022-01-31 14:24:06 +01:00
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
2022-04-13 12:06:32 +02:00
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2022-01-31 14:24:06 +01:00
|
|
|
|
exit 1
|
|
|
|
|
}
|