mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-25 08:09:17 +01:00
Updated new-user.ps1
This commit is contained in:
parent
7d34c7cdf5
commit
587c0824b9
@ -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])"
|
||||||
|
Loading…
Reference in New Issue
Block a user