Skip to content

Commit 85a7d22

Browse files
committed
Update Invoke-LocalUserManagement
rename, align help info, bump, etc.
1 parent 4b47054 commit 85a7d22

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed

ps-win-groups-users/Manage-LocalUser.ps1 renamed to ps-win-groups-users/Invoke-LocalUserManagement.ps1

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
1-
Function Manage-LocalUser {
1+
Function Invoke-LocalUserManagement {
22
<#
33
.SYNOPSIS
4-
Manage-LocalUser is a PowerShell function for performing various user management tasks on the local Windows machine. It supports actions such as resetting passwords, adding users, removing users, importing/exporting user data to/from CSV, checking user lockout status, and more.
4+
Performs various management operations on local users.
55
66
.DESCRIPTION
7-
Manage-LocalUser is a versatile utility that simplifies common tasks related to local user management. It provides a range of actions for modifying and querying local user accounts on a Windows system.
7+
This function allows performing actions such as resetting passwords, adding or removing users, getting user information, exporting data to CSV, and more, for local users on a system.
88
99
.PARAMETER Action
10-
Mandatory - Choose from a list of predefined actions such as "ResetPassword," "AddUser," "RemoveUser," "AddUsers," "RemoveUsers," "GetUsers," "GetMembers," "ExportCSV," "ImportCSV," "CheckLock," and more.
11-
.PARAMETER Username
12-
Mandatory - the username or usernames on which the action should be performed. This can be a single username or an array of usernames.
10+
Action to perform, available include "ResetPassword", "AddUser", "RemoveUser", "AddUsers", "RemoveUsers", "GetUsers", "GetMembers", "ExportCSV", "ImportCSV", "CheckLock", "ProgressReporting", "Logging", "Comments", "Automation", "InventoryFile", "ErrorHandling", "Authentication", "InputValidation", and "Rollback".
11+
.PARAMETER User
12+
Specifies the user or users on which the action will be performed.
1313
.PARAMETER GroupName
14-
NotMandatory - (For "AddUser" and "RemoveUser" actions) Specifies the name of the group to which the user should be added or removed.
15-
.PARAMETER Password
16-
NotMandatory - specifies the password to set for the user(s). Only used in actions that require password modification.
14+
Specifies the group or groups to which the user belongs.
15+
.PARAMETER Pass
16+
Specifies the password to set for the user.
1717
.PARAMETER UserMayNotChangePassword
18-
NotMandatory - indicates that the user(s) should not be allowed to change their password. Only used in actions that require password modification.
18+
Indicates whether the user is allowed to change their password.
1919
.PARAMETER PasswordNeverExpires
20-
NotMandatory - indicates that the user(s) should have passwords set to never expire. Only used in actions that require password modification.
20+
Indicates whether the user's password should never expire.
2121
.PARAMETER AccountNeverExpires
22-
NotMandatory - indicates that the user(s) should have accounts set to never expire. Only used in actions that require account modification.
22+
Indicates whether the user's account should never expire.
2323
.PARAMETER Description
24-
NotMandatory - description to associate with the user(s). Only used in actions that require user creation or modification.
24+
Specifies the description for the user account.
2525
.PARAMETER Disabled
26-
NotMandatory - (For "AddUser" and "AddUsers" actions) Indicates that the user(s) should be created as disabled accounts.
26+
Indicates whether the user account is disabled.
2727
.PARAMETER File
28-
NotMandatory - (For "ImportCSV" and "ExportCSV" actions) Specifies the path to the CSV file to import user data from or export data to.
28+
Path to a file used for importing or exporting data.
2929
.PARAMETER LogFile
30-
NotMandatory - specifies the path for the log file where operation results and error messages will be recorded.
30+
Specifies the path to the log file.
31+
32+
.EXAMPLE
33+
Invoke-LocalUserManagement -Action ResetPassword -User JohnDoe -Pass "NewPassword123"
3134
3235
.NOTES
33-
v0.0.2
36+
v0.0.4
3437
#>
3538
[CmdletBinding()]
36-
param(
39+
param (
3740
[Parameter(Mandatory = $true)]
3841
[ValidateSet(
3942
"ResetPassword", "AddUser", "RemoveUser", "AddUsers", "RemoveUsers",
@@ -45,13 +48,13 @@ Function Manage-LocalUser {
4548
[string]$Action,
4649

4750
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
48-
[string[]]$Username,
51+
[string[]]$User,
4952

5053
[Parameter(Mandatory = $false)]
5154
[string[]]$GroupName,
5255

5356
[Parameter(Mandatory = $false)]
54-
[string]$Password,
57+
[string]$Pass,
5558

5659
[Parameter(Mandatory = $false)]
5760
[switch]$UserMayNotChangePassword,
@@ -90,10 +93,10 @@ Function Manage-LocalUser {
9093
}
9194
}
9295
"ResetPassword" {
93-
$Username | ForEach-Object {
94-
$params = @{
96+
$User | ForEach-Object {
97+
$Params = @{
9598
Name = $_
96-
Password = $Password | ConvertTo-SecureString -AsPlainText -Force
99+
Password = $Pass | ConvertTo-SecureString -AsPlainText -Force
97100
UserMayChangePassword = !$UserMayNotChangePassword.IsPresent
98101
PasswordNeverExpires = $PasswordNeverExpires.IsPresent
99102
AccountNeverExpires = $AccountNeverExpires.IsPresent
@@ -102,7 +105,7 @@ Function Manage-LocalUser {
102105
Verbose = $true
103106
}
104107
try {
105-
Set-LocalUser @params
108+
Set-LocalUser @Params
106109
}
107110
catch {
108111
Write-Warning -Message "Failed to reset password for user $_. Error: $_"
@@ -111,15 +114,15 @@ Function Manage-LocalUser {
111114
}
112115
}
113116
"AddUser" {
114-
$Username | ForEach-Object {
117+
$User | ForEach-Object {
115118
if (Get-LocalUser -Name $_) {
116119
Write-Warning -Message "$_ already exists, skipping..."
117120
$Result.Add("Exists")
118121
return
119122
}
120-
$params = @{
123+
$Params = @{
121124
Name = $_
122-
Password = $Password | ConvertTo-SecureString -AsPlainText -Force
125+
Password = $Pass | ConvertTo-SecureString -AsPlainText -Force
123126
UserMayNotChangePassword = $UserMayNotChangePassword.IsPresent
124127
PasswordNeverExpires = $PasswordNeverExpires.IsPresent
125128
AccountNeverExpires = $AccountNeverExpires.IsPresent
@@ -129,7 +132,7 @@ Function Manage-LocalUser {
129132
Verbose = $true
130133
}
131134
try {
132-
New-LocalUser @params
135+
New-LocalUser @Params
133136
if ((Get-LocalGroupMember -Group $GroupName | Select-Object Name | Where-Object { $_.Name -eq $_ }).Count -eq 0) {
134137
Write-Verbose "Adding user to group $GroupName..."
135138
Add-LocalGroupMember -Group $GroupName -Member $_ -ErrorAction SilentlyContinue -Verbose
@@ -147,19 +150,19 @@ Function Manage-LocalUser {
147150
}
148151
}
149152
"RemoveUser" {
150-
$Username | ForEach-Object {
153+
$User | ForEach-Object {
151154
if (!(Get-LocalUser -Name $_)) {
152155
Write-Warning -Message "$_ does not exist, skipping..."
153156
$Result.Add("NotExists")
154157
return
155158
}
156-
$params = @{
159+
$Params = @{
157160
Name = $_
158161
ErrorAction = "SilentlyContinue"
159162
Verbose = $true
160163
}
161164
try {
162-
Remove-LocalUser @params
165+
Remove-LocalUser @Params
163166
if ((Get-LocalGroupMember -Group $GroupName | Select-Object Name | Where-Object { $_.Name -eq $_ }).Count -ne 0) {
164167
Write-Verbose "Removing user from group $GroupName..."
165168
Remove-LocalGroupMember -Group $GroupName -Member $_ -ErrorAction SilentlyContinue -Verbose
@@ -175,9 +178,9 @@ Function Manage-LocalUser {
175178
"AddUsers" {
176179
$Users = Get-Content -Path $File
177180
foreach ($User in $Users) {
178-
$params = @{
181+
$Params = @{
179182
Name = $User
180-
Password = $Password | ConvertTo-SecureString -AsPlainText -Force
183+
Password = $Pass | ConvertTo-SecureString -AsPlainText -Force
181184
UserMayNotChangePassword = $UserMayNotChangePassword.IsPresent
182185
PasswordNeverExpires = $PasswordNeverExpires.IsPresent
183186
AccountNeverExpires = $AccountNeverExpires.IsPresent
@@ -187,7 +190,7 @@ Function Manage-LocalUser {
187190
Verbose = $true
188191
}
189192
try {
190-
New-LocalUser @params
193+
New-LocalUser @Params
191194
if ((Get-LocalGroupMember -Group $GroupName | Select-Object Name | Where-Object { $_.Name -eq $User }).Count -eq 0) {
192195
Write-Verbose "Adding user $User to group $GroupName..."
193196
Add-LocalGroupMember -Group $GroupName -Member $User -ErrorAction SilentlyContinue -Verbose
@@ -207,13 +210,13 @@ Function Manage-LocalUser {
207210
"RemoveUsers" {
208211
$Users = Get-Content -Path $File
209212
foreach ($User in $Users) {
210-
$params = @{
213+
$Params = @{
211214
Name = $User
212215
ErrorAction = "SilentlyContinue"
213216
Verbose = $true
214217
}
215218
try {
216-
Remove-LocalUser @params
219+
Remove-LocalUser @Params
217220
if ((Get-LocalGroupMember -Group $GroupName | Select-Object Name | Where-Object { $_.Name -eq $User }).Count -ne 0) {
218221
Write-Verbose "Removing user $User from group $GroupName..."
219222
Remove-LocalGroupMember -Group $GroupName -Member $User -ErrorAction SilentlyContinue -Verbose
@@ -248,13 +251,13 @@ Function Manage-LocalUser {
248251
}
249252
}
250253
"CheckLock" {
251-
$Username | ForEach-Object {
252-
$params = @{
254+
$User | ForEach-Object {
255+
$Params = @{
253256
Name = $_
254257
ErrorAction = "SilentlyContinue"
255258
Verbose = $true
256259
}
257-
$User = Get-LocalUser @params
260+
$User = Get-LocalUser @Params
258261
if ($User) {
259262
if ($User.LockoutEnabled) {
260263
$Result.Add("$User.Name is locked out")

0 commit comments

Comments
 (0)