Created
December 19, 2011 14:53
-
-
Save mdnmdn/1497539 to your computer and use it in GitHub Desktop.
Powershell windows user administration playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$hostname = hostname | |
#create new user | |
$comp = [adsi] "WinNT://$hostname" | |
$user = $comp.Create("User", "mdn") | |
$user.Put("description", "$username") | |
$user.SetPassword("Password1") | |
$user.SetInfo() | |
$user.psbase.invokeset("AccountDisabled", "False") | |
$user.SetInfo() | |
#create new group | |
$group = $comp.Create("Group", "group1") | |
$group.description = "Group 1" | |
$group.SetInfo() | |
# users list | |
$comp.psbase.Children | Where-Object { $_.psbase.schemaclassname -eq 'user' } | Format-Table Name, Description -autoSize | |
#group list | |
$comp.psbase.Children | Where-Object { $_.psbase.schemaclassname -eq 'group' } | Format-Table Name, Description -autoSize | |
# user list | |
$users = $comp.psbase.Children | Where-Object { $_.psbase.schemaclassname -eq 'user' } | |
$users | Where-Object {$_.name -like '*mene*' } | Select-Object {$_.name} | |
#add user to group | |
# note: use hostname in path | |
$admins = [adsi] "WinNT://spdpv/Administrators" | |
$user = [adsi] "WinNT://spdpv/mdn" | |
$admins.add($user.path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment