![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Windows XP, Users and Groups I'm trying to write scripts for managing Windows XP's users and groups. I can create user: $ds=[ADSI]"WinNT://host" $user=$ds.psbase.Children.Add("new_user","User") $user.psbase.CommitChanges() $user.SetPassword("new_pass") $user.psbase.CommitChanges() But I can't add user to group. I tried this: $user.PSBase.Children.Add("Administratorzy","Group") But I got this: Exception calling "Add" with "2" argument(s): "Obiekt usługi Active Directory z lokalizowany w ścieżce WinNT://workgroup/host/new_user nie jest kontenerem." At line:1 char:26 + $user.PSBase.Children.Add( <<<< "Administratorzy","Group") In English: Active Directry object is not a container. It's horrible! I can't find anywhere how to add user to group. If someone can help me, I will be happy. P.S. I want to apologise for my English. I'm from Poland (and I'm proud of it!) |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Windows XP, Users and Groups Two Problems One problem is that you need to use the User Path i.e. "WinNT://$server/$User" Two... you need to add the user via the group object. Here is my method ================ Param([string]$user,[string]$group,[string]$server) If(!($server)){$server = get-content env:COMPUTERNAME} Write-Host "" Write-Host "Adding User [$user] to group [$group]" Write-Host "----------------------------------------------" -ForegroundColor gray $ary = @() $srv = [ADSI]("WinNT://$server,computer") $u = [ADSI]("WinNT://$server/$User,User") $ary += $u.psbase.path # Getting Group and Adding User $g = [ADSI]("WinNT://$server/$group,group") $g.psbase.invoke("add",$ary) Write-Host "If no Exception... User Added" -ForegroundColor Green "MaciekN" <maciek43360@xxxxxx> wrote in message news:%23CUh8Y6%23HHA.2268@xxxxxx Quote: > I'm trying to write scripts for managing Windows XP's users and groups. > I can create user: > > $ds=[ADSI]"WinNT://host" > $user=$ds.psbase.Children.Add("new_user","User") > $user.psbase.CommitChanges() > $user.SetPassword("new_pass") > $user.psbase.CommitChanges() > > But I can't add user to group. > I tried this: > > $user.PSBase.Children.Add("Administratorzy","Group") > > But I got this: > > Exception calling "Add" with "2" argument(s): "Obiekt usługi Active > Directory z > lokalizowany w ścieżce WinNT://workgroup/host/new_user nie jest > kontenerem." > At line:1 char:26 > > + $user.PSBase.Children.Add( <<<< "Administratorzy","Group") > > > In English: Active Directry object is not a container. > > It's horrible! I can't find anywhere how to add user to group. If > someone can help me, I will be happy. > > P.S. I want to apologise for my English. I'm from Poland (and I'm proud > of it!) > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Windows XP, Users and Groups I was just looking through my method... it is an old one (should still work)... here is a revised version function Add-UsertoLocalGroup{ Param([string]$user,[string]$group,[string]$server) If(!($server)){$server = get-content env:COMPUTERNAME} Write-Host "Adding User [$user] to group [$group]" Write-Host "----------------------------------------------" -ForegroundColor gray $srv = [ADSI]("WinNT://$server,computer") $u = [ADSI]("WinNT://$server/$User,User") # Getting Group and Adding User $g = [ADSI]("WinNT://$server/$group,group") $g.psbase.invoke("add",$u.psbase.path) } "MaciekN" <maciek43360@xxxxxx> wrote in message news:%23CUh8Y6%23HHA.2268@xxxxxx Quote: > I'm trying to write scripts for managing Windows XP's users and groups. > I can create user: > > $ds=[ADSI]"WinNT://host" > $user=$ds.psbase.Children.Add("new_user","User") > $user.psbase.CommitChanges() > $user.SetPassword("new_pass") > $user.psbase.CommitChanges() > > But I can't add user to group. > I tried this: > > $user.PSBase.Children.Add("Administratorzy","Group") > > But I got this: > > Exception calling "Add" with "2" argument(s): "Obiekt usługi Active > Directory z > lokalizowany w ścieżce WinNT://workgroup/host/new_user nie jest > kontenerem." > At line:1 char:26 > > + $user.PSBase.Children.Add( <<<< "Administratorzy","Group") > > > In English: Active Directry object is not a container. > > It's horrible! I can't find anywhere how to add user to group. If > someone can help me, I will be happy. > > P.S. I want to apologise for my English. I'm from Poland (and I'm proud > of it!) > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Windows XP, Users and Groups Thanks! It works! Brandon Shell pisze: Quote: > Two Problems > One problem is that you need to use the User Path i.e. > "WinNT://$server/$User" > Two... you need to add the user via the group object. > > Here is my method > ================ > Param([string]$user,[string]$group,[string]$server) > If(!($server)){$server = get-content env:COMPUTERNAME} > Write-Host "" > Write-Host "Adding User [$user] to group [$group]" > Write-Host "----------------------------------------------" > -ForegroundColor gray > $ary = @() > $srv = [ADSI]("WinNT://$server,computer") > $u = [ADSI]("WinNT://$server/$User,User") > $ary += $u.psbase.path > > # Getting Group and Adding User > $g = [ADSI]("WinNT://$server/$group,group") > $g.psbase.invoke("add",$ary) > Write-Host "If no Exception... User Added" -ForegroundColor Green > > "MaciekN" <maciek43360@xxxxxx> wrote in message > news:%23CUh8Y6%23HHA.2268@xxxxxx Quote: >> I'm trying to write scripts for managing Windows XP's users and groups. >> I can create user: >> >> $ds=[ADSI]"WinNT://host" >> $user=$ds.psbase.Children.Add("new_user","User") >> $user.psbase.CommitChanges() >> $user.SetPassword("new_pass") >> $user.psbase.CommitChanges() >> >> But I can't add user to group. >> I tried this: >> >> $user.PSBase.Children.Add("Administratorzy","Group") >> >> But I got this: >> >> Exception calling "Add" with "2" argument(s): "Obiekt usługi Active >> Directory z >> lokalizowany w ścieżce WinNT://workgroup/host/new_user nie jest >> kontenerem." >> At line:1 char:26 >> >> + $user.PSBase.Children.Add( <<<< "Administratorzy","Group") >> >> >> In English: Active Directry object is not a container. >> >> It's horrible! I can't find anywhere how to add user to group. If >> someone can help me, I will be happy. >> >> P.S. I want to apologise for my English. I'm from Poland (and I'm proud >> of it!) >> |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Windows XP, Users and Groups I have one more question. How can I retrieve memebers of group? |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Windows XP, Users and Groups I wrote this a long time ago... so long someone had to tell me it was on my blog But here you goFound Here http://bsonposh.com/modules/wordpress/?page_id=22 along with lots of other "functions" ######################################################################### function Get-GroupMembers{ # From: Brandon Shell # Example: # -- To List Users of a group # PS> Get-GroupMembers -group Administrators -server myserver1 # -- To Check if User is member of Group # PS> Get-GroupMembers -group Administrators -server myserver -user jsmith ################################################################# Param([string]$group,[string]$server,[string]$user) # Check if $server has value. If not set to Local Host Name If(!($server)){$server = get-content env:COMPUTERNAME} # Getting Group Object $g = [ADSI]("WinNT://$server/$group,group") # Getting Member User Names $ulist = $g.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)} # If User is specified we check each member for match if($user) { foreach($u in $ulist) { if($u -eq $user){$found = $true} } if($found){Write-Host "User [$user] Found" -ForegroundColor green;$true} else{Write-Host "User [$user] NOT found!" -ForegroundColor red;$false} } else { # No user specified... Output Member list $ulist } } "MaciekN" <maciek43360@xxxxxx> wrote in message news:uqgsVHB$HHA.320@xxxxxx Quote: >I have one more question. How can I retrieve memebers of group? |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Count a users groups | VB Script | |||
| Vista Users and Groups | Vista security | |||
| Remove Users From All Groups | PowerShell | |||
| Users&Groups | Vista General | |||
| Local Users and Groups | Vista General | |||