-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalUsersModule.ps1
More file actions
36 lines (35 loc) · 1.42 KB
/
Copy pathLocalUsersModule.ps1
File metadata and controls
36 lines (35 loc) · 1.42 KB
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
Function Create-RemoteLocalUser {
param ($ComputerName,$Username,$Password)
Foreach ($computer in $computers) {
$users = $null
$computer = [ADSI]“WinNT://$computer”
Try {
$users = $computer.psbase.children | select -expand name
if ($users -like $username) {
Write-Host "$username already exists"
} Else {
$user_obj = $computer.Create(“user”, “$username”)
$user_obj.SetPassword($password)
$user_obj.SetInfo()
$user_obj.Put(“description”, “$username”)
$user_obj.SetInfo()
$user_obj.psbase.invokeset(“AccountDisabled”, “False”)
$user_obj.SetInfo()
$users = $computer.psbase.children | select -expand name
if ($users -like $username) {
Write-Host "$username has been created on $($computer.name)"
} Else {
Write-Host "$username has not been created on $($computer.name)"
}
}
} Catch {
Write-Host "Error creating $username on $($computer.path): $($Error[0].Exception.Message)"
}
}
}
Function Add-RemoteLocalAdmin {
param ($UserName)
$AdminGroup = [ADSI]"WinNT://$ComputerName/Administrators,group"
$User = [ADSI]"WinNT://$ComputerName/$UserName,user"
$AdminGroup.Add($User.Path)
}