-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabadmin-config-user.ps1
75 lines (60 loc) · 1.84 KB
/
labadmin-config-user.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Config some user login authentication/login settings (hide from login list, remove password, disable account, etc).
.PARAMETER UserName
Username of account to config
.PARAMETER SetPassword
Config new account password
.PARAMETER NoPassword
Remove user password for login without password
.PARAMETER Hide
Hide user from login list
.PARAMETER Unhide
Unhide user from login list
.PARAMETER Disable
Disable user account
.PARAMETER Enable
Enable user account
.NOTES
File Name: labadmin-config-user.ps1
Author : Leonardo Marco
#>
Param(
[Parameter(Mandatory=$true)]
[String]$UserName,
[parameter(ParameterSetName='password')]
[String]$SetPassword,
[Parameter(ParameterSetName='nopass')]
[Switch]$NoPassword,
[Parameter(ParameterSetName='hide')]
[Switch]$Hide,
[Parameter(ParameterSetName='unhide')]
[Switch]$Unhide,
[Parameter(ParameterSetName='disable')]
[Switch]$Disable,
[Parameter(ParameterSetName='enable')]
[Switch]$Enable
)
Get-LocalUser -Name $UserName -ErrorAction Stop | Out-Null
# HIDE/UNHIDE
if($Hide) {
New-Item 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList' -Force | New-ItemProperty -Name $UserName -Value 0 -PropertyType DWord -Force
} elseif($Unhide) {
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList" -Name $UserName -Force
}
# ENABLE/DISABLE
if($Disable) {
Disable-LocalUser -Name $UserName
Get-LocalUser -Name $UserName
} elseif($Enable) {
Enable-LocalUser -Name $UserName
Get-LocalUser -Name $UserName
}
# NOPASSWORD/SETPASSWORD
if($NoPassword) {
Set-LocalUser -Name $UserName -Password ([securestring]::new())
} elseif($SetPassword){
$ss=$SetPassword|ConvertTo-SecureString -AsPlainText -Force
Set-LocalUser -Name $UserName -Password $ss
}