Funkcija za kreiranje lokalnih korisnika
function create-localuser {
param($computer="localhost", $user, $password, [switch] $Admin)
$objOu = [ADSI]"WinNT://$computer"
$objUser = $objOU.Create("User", $user)
$objUser.setpassword($password)
$objUser.SetInfo()
$objUser.description = "User"
$objUser.SetInfo()
if($Admin){
Add-LocalGroupMember -Group Administrators -Member $user}
else{}
}
dodat je switch -Admin koji odredjuje da li ce korisnik biti dodat u grupu lokalnih administratora.
evo i primera kako je ja koristim
create-localuser -computer localhost -user ntest -password 123123123 -Admin
ili, ukoliko hocu vise korisnika
$users = import-csv C:\test\users.csv
foreach($user_full in $users){
$user = $user_full.user
$password = $user_full.password
create-localuser -user $user -password $password -Admin
}
struktura CSV fajla je
user,password
function create-localuser {
param($computer="localhost", $user, $password, [switch] $Admin)
$objOu = [ADSI]"WinNT://$computer"
$objUser = $objOU.Create("User", $user)
$objUser.setpassword($password)
$objUser.SetInfo()
$objUser.description = "User"
$objUser.SetInfo()
if($Admin){
Add-LocalGroupMember -Group Administrators -Member $user}
else{}
}
dodat je switch -Admin koji odredjuje da li ce korisnik biti dodat u grupu lokalnih administratora.
evo i primera kako je ja koristim
create-localuser -computer localhost -user ntest -password 123123123 -Admin
ili, ukoliko hocu vise korisnika
$users = import-csv C:\test\users.csv
foreach($user_full in $users){
$user = $user_full.user
$password = $user_full.password
create-localuser -user $user -password $password -Admin
}
struktura CSV fajla je
user,password