![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| Guest | local user please Sorry for the repost but does any one know how to create a local user in powershecll |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: local user please Some Functions I wrote for this... they all use WinNT instead of LDAP so you can run locally. function add-User{ Param([string]$user,[string]$password,[string]$server) If(!($server)){$server = get-content env:COMPUTERNAME} $tUser = [ADSI]("WinNT://$server,computer") $newuser = $tUser.psbase.children.add("$user","user") $newuser.psbase.invoke("SetPassword",$password) $newuser.psbase.CommitChanges() } function add-AdminUser{ Param([string]$user,[string]$password,[string]$server) If(!($server)){$server = get-content env:COMPUTERNAME} $tUser = [ADSI]("WinNT://$server,computer") $newuser = $tUser.psbase.children.add("$user","user") $newuser.psbase.invoke("SetPassword",$password) $newuser.psbase.CommitChanges() $ary = @() $ary += $newuser.psbase.path # Getting Group and Adding User $g = [ADSI]("WinNT://$server/Administrators,group") $g.psbase.invoke("add",$ary) } function add-UsertoGroup{ 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) #if(!($g.psbase.invoke("isMember",$ary))) {$g.psbase.invoke("add",$ary)} #else {Write-Host "User already a Member" -ForegroundColor yellow} # Checking Group for User #if(!($g.psbase.invoke("IsMember",$ary))){Write-Host "User Add Failed!" -ForegroundColor Red} #else{Write-Host "User Added." -ForegroundColor green} Write-Host "If no Exception... User Added" -ForegroundColor Green } -- Brandon Shell --------------- Stop by my blog some time ![]() Blog: http://www.bsonposh.com/ PSH Scripts Project: www.codeplex.com/psobject -------------------------------------- "frank" <frank@discussions.microsoft.com> wrote in message news:50ABD76E-C714-47A7-8032-4332023897C2@microsoft.com... > Sorry for the repost but does any one know how to create a local user > in powershecll |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: local user please Disclaimer... this was before the valid -whatif push by the dev team. I STRONGLY recommend using Jeffrey's should-process script noted here: http://blogs.msdn.com/powershell/default.aspx -- Brandon Shell --------------- Stop by my blog some time ![]() Blog: http://www.bsonposh.com/ PSH Scripts Project: www.codeplex.com/psobject -------------------------------------- "Brandon Shell" <tshell.mask@gmail.com> wrote in message news:eh1l3LBYHHA.4440@TK2MSFTNGP03.phx.gbl... > Some Functions I wrote for this... they all use WinNT instead of LDAP so > you can run locally. > > function add-User{ > Param([string]$user,[string]$password,[string]$server) > If(!($server)){$server = get-content env:COMPUTERNAME} > $tUser = [ADSI]("WinNT://$server,computer") > $newuser = $tUser.psbase.children.add("$user","user") > $newuser.psbase.invoke("SetPassword",$password) > $newuser.psbase.CommitChanges() > } > > function add-AdminUser{ > Param([string]$user,[string]$password,[string]$server) > If(!($server)){$server = get-content env:COMPUTERNAME} > $tUser = [ADSI]("WinNT://$server,computer") > $newuser = $tUser.psbase.children.add("$user","user") > $newuser.psbase.invoke("SetPassword",$password) > $newuser.psbase.CommitChanges() > $ary = @() > $ary += $newuser.psbase.path > # Getting Group and Adding User > $g = [ADSI]("WinNT://$server/Administrators,group") > $g.psbase.invoke("add",$ary) > } > > function add-UsertoGroup{ > 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) > #if(!($g.psbase.invoke("isMember",$ary))) {$g.psbase.invoke("add",$ary)} > #else {Write-Host "User already a Member" -ForegroundColor yellow} > # Checking Group for User > #if(!($g.psbase.invoke("IsMember",$ary))){Write-Host "User Add > Failed!" -ForegroundColor Red} > #else{Write-Host "User Added." -ForegroundColor green} > Write-Host "If no Exception... User Added" -ForegroundColor Green > } > > -- > Brandon Shell > --------------- > Stop by my blog some time ![]() > Blog: http://www.bsonposh.com/ > PSH Scripts Project: www.codeplex.com/psobject > -------------------------------------- > > "frank" <frank@discussions.microsoft.com> wrote in message > news:50ABD76E-C714-47A7-8032-4332023897C2@microsoft.com... >> Sorry for the repost but does any one know how to create a local user >> in powershecll > |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: local user please That looks like a cut/paste problem That should be on the same line as the write-host. Write-Host "----------------------------------------------" -ForegroundColor gray should be Write-Host "--------------------" -ForegroundColor gray -- Brandon Shell --------------- Stop by my blog some time ![]() Blog: http://www.bsonposh.com/ PSH Scripts Project: www.codeplex.com/psobject -------------------------------------- "frank" <frank@discussions.microsoft.com> wrote in message news:72106A5A-4FCC-4882-B587-3389D0E16D6D@microsoft.com... >I get an error > You must provide a value expersion on the right-hand side of -f operator > "---------" > -Fo <<<< reground color gray > > > > "Brandon Shell" wrote: > >> Disclaimer... this was before the valid -whatif push by the dev team. >> >> I STRONGLY recommend using Jeffrey's should-process script noted here: >> http://blogs.msdn.com/powershell/default.aspx >> >> -- >> Brandon Shell >> --------------- >> Stop by my blog some time ![]() >> Blog: http://www.bsonposh.com/ >> PSH Scripts Project: www.codeplex.com/psobject >> -------------------------------------- >> >> "Brandon Shell" <tshell.mask@gmail.com> wrote in message >> news:eh1l3LBYHHA.4440@TK2MSFTNGP03.phx.gbl... >> > Some Functions I wrote for this... they all use WinNT instead of LDAP >> > so >> > you can run locally. >> > >> > function add-User{ >> > Param([string]$user,[string]$password,[string]$server) >> > If(!($server)){$server = get-content env:COMPUTERNAME} >> > $tUser = [ADSI]("WinNT://$server,computer") >> > $newuser = $tUser.psbase.children.add("$user","user") >> > $newuser.psbase.invoke("SetPassword",$password) >> > $newuser.psbase.CommitChanges() >> > } >> > >> > function add-AdminUser{ >> > Param([string]$user,[string]$password,[string]$server) >> > If(!($server)){$server = get-content env:COMPUTERNAME} >> > $tUser = [ADSI]("WinNT://$server,computer") >> > $newuser = $tUser.psbase.children.add("$user","user") >> > $newuser.psbase.invoke("SetPassword",$password) >> > $newuser.psbase.CommitChanges() >> > $ary = @() >> > $ary += $newuser.psbase.path >> > # Getting Group and Adding User >> > $g = [ADSI]("WinNT://$server/Administrators,group") >> > $g.psbase.invoke("add",$ary) >> > } >> > >> > function add-UsertoGroup{ >> > 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) >> > #if(!($g.psbase.invoke("isMember",$ary))) >> > {$g.psbase.invoke("add",$ary)} >> > #else {Write-Host "User already a Member" -ForegroundColor yellow} >> > # Checking Group for User >> > #if(!($g.psbase.invoke("IsMember",$ary))){Write-Host "User Add >> > Failed!" -ForegroundColor Red} >> > #else{Write-Host "User Added." -ForegroundColor green} >> > Write-Host "If no Exception... User Added" -ForegroundColor Green >> > } >> > >> > -- >> > Brandon Shell >> > --------------- >> > Stop by my blog some time ![]() >> > Blog: http://www.bsonposh.com/ >> > PSH Scripts Project: www.codeplex.com/psobject >> > -------------------------------------- >> > >> > "frank" <frank@discussions.microsoft.com> wrote in message >> > news:50ABD76E-C714-47A7-8032-4332023897C2@microsoft.com... >> >> Sorry for the repost but does any one know how to create a local user >> >> in powershecll >> > >> >> |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: local user please I get an error You must provide a value expersion on the right-hand side of -f operator "---------" -Fo <<<< reground color gray "Brandon Shell" wrote: > Disclaimer... this was before the valid -whatif push by the dev team. > > I STRONGLY recommend using Jeffrey's should-process script noted here: > http://blogs.msdn.com/powershell/default.aspx > > -- > Brandon Shell > --------------- > Stop by my blog some time ![]() > Blog: http://www.bsonposh.com/ > PSH Scripts Project: www.codeplex.com/psobject > -------------------------------------- > > "Brandon Shell" <tshell.mask@gmail.com> wrote in message > news:eh1l3LBYHHA.4440@TK2MSFTNGP03.phx.gbl... > > Some Functions I wrote for this... they all use WinNT instead of LDAP so > > you can run locally. > > > > function add-User{ > > Param([string]$user,[string]$password,[string]$server) > > If(!($server)){$server = get-content env:COMPUTERNAME} > > $tUser = [ADSI]("WinNT://$server,computer") > > $newuser = $tUser.psbase.children.add("$user","user") > > $newuser.psbase.invoke("SetPassword",$password) > > $newuser.psbase.CommitChanges() > > } > > > > function add-AdminUser{ > > Param([string]$user,[string]$password,[string]$server) > > If(!($server)){$server = get-content env:COMPUTERNAME} > > $tUser = [ADSI]("WinNT://$server,computer") > > $newuser = $tUser.psbase.children.add("$user","user") > > $newuser.psbase.invoke("SetPassword",$password) > > $newuser.psbase.CommitChanges() > > $ary = @() > > $ary += $newuser.psbase.path > > # Getting Group and Adding User > > $g = [ADSI]("WinNT://$server/Administrators,group") > > $g.psbase.invoke("add",$ary) > > } > > > > function add-UsertoGroup{ > > 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) > > #if(!($g.psbase.invoke("isMember",$ary))) {$g.psbase.invoke("add",$ary)} > > #else {Write-Host "User already a Member" -ForegroundColor yellow} > > # Checking Group for User > > #if(!($g.psbase.invoke("IsMember",$ary))){Write-Host "User Add > > Failed!" -ForegroundColor Red} > > #else{Write-Host "User Added." -ForegroundColor green} > > Write-Host "If no Exception... User Added" -ForegroundColor Green > > } > > > > -- > > Brandon Shell > > --------------- > > Stop by my blog some time ![]() > > Blog: http://www.bsonposh.com/ > > PSH Scripts Project: www.codeplex.com/psobject > > -------------------------------------- > > > > "frank" <frank@discussions.microsoft.com> wrote in message > > news:50ABD76E-C714-47A7-8032-4332023897C2@microsoft.com... > >> Sorry for the repost but does any one know how to create a local user > >> in powershecll > > > > |
My System Specs![]() |
| | #6 (permalink) |
| Guest | Re: local user please different error now Incomplete string taken +F <<< ailed -foregroundcolor red I type in ./new.ps1 testuser 1233456 grouop server "Brandon Shell" wrote: > That looks like a cut/paste problem > > That should be on the same line as the write-host. > Write-Host > "----------------------------------------------" -ForegroundColor gray > should be > Write-Host "--------------------" -ForegroundColor gray > > > -- > Brandon Shell > --------------- > Stop by my blog some time ![]() > Blog: http://www.bsonposh.com/ > PSH Scripts Project: www.codeplex.com/psobject > -------------------------------------- > > "frank" <frank@discussions.microsoft.com> wrote in message > news:72106A5A-4FCC-4882-B587-3389D0E16D6D@microsoft.com... > >I get an error > > You must provide a value expersion on the right-hand side of -f operator > > "---------" > > -Fo <<<< reground color gray > > > > > > > > "Brandon Shell" wrote: > > > >> Disclaimer... this was before the valid -whatif push by the dev team. > >> > >> I STRONGLY recommend using Jeffrey's should-process script noted here: > >> http://blogs.msdn.com/powershell/default.aspx > >> > >> -- > >> Brandon Shell > >> --------------- > >> Stop by my blog some time ![]() > >> Blog: http://www.bsonposh.com/ > >> PSH Scripts Project: www.codeplex.com/psobject > >> -------------------------------------- > >> > >> "Brandon Shell" <tshell.mask@gmail.com> wrote in message > >> news:eh1l3LBYHHA.4440@TK2MSFTNGP03.phx.gbl... > >> > Some Functions I wrote for this... they all use WinNT instead of LDAP > >> > so > >> > you can run locally. > >> > > >> > function add-User{ > >> > Param([string]$user,[string]$password,[string]$server) > >> > If(!($server)){$server = get-content env:COMPUTERNAME} > >> > $tUser = [ADSI]("WinNT://$server,computer") > >> > $newuser = $tUser.psbase.children.add("$user","user") > >> > $newuser.psbase.invoke("SetPassword",$password) > >> > $newuser.psbase.CommitChanges() > >> > } > >> > > >> > function add-AdminUser{ > >> > Param([string]$user,[string]$password,[string]$server) > >> > If(!($server)){$server = get-content env:COMPUTERNAME} > >> > $tUser = [ADSI]("WinNT://$server,computer") > >> > $newuser = $tUser.psbase.children.add("$user","user") > >> > $newuser.psbase.invoke("SetPassword",$password) > >> > $newuser.psbase.CommitChanges() > >> > $ary = @() > >> > $ary += $newuser.psbase.path > >> > # Getting Group and Adding User > >> > $g = [ADSI]("WinNT://$server/Administrators,group") > >> > $g.psbase.invoke("add",$ary) > >> > } > >> > > >> > function add-UsertoGroup{ > >> > 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) > >> > #if(!($g.psbase.invoke("isMember",$ary))) > >> > {$g.psbase.invoke("add",$ary)} > >> > #else {Write-Host "User already a Member" -ForegroundColor yellow} > >> > # Checking Group for User > >> > #if(!($g.psbase.invoke("IsMember",$ary))){Write-Host "User Add > >> > Failed!" -ForegroundColor Red} > >> > #else{Write-Host "User Added." -ForegroundColor green} > >> > Write-Host "If no Exception... User Added" -ForegroundColor Green > >> > } > >> > > >> > -- > >> > Brandon Shell > >> > --------------- > >> > Stop by my blog some time ![]() > >> > Blog: http://www.bsonposh.com/ > >> > PSH Scripts Project: www.codeplex.com/psobject > >> > -------------------------------------- > >> > > >> > "frank" <frank@discussions.microsoft.com> wrote in message > >> > news:50ABD76E-C714-47A7-8032-4332023897C2@microsoft.com... > >> >> Sorry for the repost but does any one know how to create a local user > >> >> in powershecll > >> > > >> > >> > > |
My System Specs![]() |
| | #7 (permalink) |
| Guest | Re: local user please Again.. same problem cut/paste is evilJust make sure any reference to -foregroundcolor is on the same line as write-host. It is a parameter. This is the line I think is erroring #if(!($g.psbase.invoke("IsMember",$ary))){Write-Host "User Add Failed!" -ForegroundColor Red} This is just a comment so you can delete the whole line or at least make it on one line -- Brandon Shell --------------- Stop by my blog some time ![]() Blog: http://www.bsonposh.com/ PSH Scripts Project: www.codeplex.com/psobject -------------------------------------- "frank" <frank@discussions.microsoft.com> wrote in message news:667FD8FA-C74D-47FA-A117-83B8D9DF1B40@microsoft.com... > different error now > > Incomplete string taken > +F <<< ailed -foregroundcolor red > > I type in ./new.ps1 testuser 1233456 grouop server > > > > "Brandon Shell" wrote: > >> That looks like a cut/paste problem >> >> That should be on the same line as the write-host. >> Write-Host >> "----------------------------------------------" -ForegroundColor gray >> should be >> Write-Host "--------------------" -ForegroundColor gray >> >> >> -- >> Brandon Shell >> --------------- >> Stop by my blog some time ![]() >> Blog: http://www.bsonposh.com/ >> PSH Scripts Project: www.codeplex.com/psobject >> -------------------------------------- >> >> "frank" <frank@discussions.microsoft.com> wrote in message >> news:72106A5A-4FCC-4882-B587-3389D0E16D6D@microsoft.com... >> >I get an error >> > You must provide a value expersion on the right-hand side of -f >> > operator >> > "---------" >> > -Fo <<<< reground color gray >> > >> > >> > >> > "Brandon Shell" wrote: >> > >> >> Disclaimer... this was before the valid -whatif push by the dev team. >> >> >> >> I STRONGLY recommend using Jeffrey's should-process script noted here: >> >> http://blogs.msdn.com/powershell/default.aspx >> >> >> >> -- >> >> Brandon Shell >> >> --------------- >> >> Stop by my blog some time ![]() >> >> Blog: http://www.bsonposh.com/ >> >> PSH Scripts Project: www.codeplex.com/psobject >> >> -------------------------------------- >> >> >> >> "Brandon Shell" <tshell.mask@gmail.com> wrote in message >> >> news:eh1l3LBYHHA.4440@TK2MSFTNGP03.phx.gbl... >> >> > Some Functions I wrote for this... they all use WinNT instead of >> >> > LDAP >> >> > so >> >> > you can run locally. >> >> > >> >> > function add-User{ >> >> > Param([string]$user,[string]$password,[string]$server) >> >> > If(!($server)){$server = get-content env:COMPUTERNAME} >> >> > $tUser = [ADSI]("WinNT://$server,computer") >> >> > $newuser = $tUser.psbase.children.add("$user","user") >> >> > $newuser.psbase.invoke("SetPassword",$password) >> >> > $newuser.psbase.CommitChanges() >> >> > } >> >> > >> >> > function add-AdminUser{ >> >> > Param([string]$user,[string]$password,[string]$server) >> >> > If(!($server)){$server = get-content env:COMPUTERNAME} >> >> > $tUser = [ADSI]("WinNT://$server,computer") >> >> > $newuser = $tUser.psbase.children.add("$user","user") >> >> > $newuser.psbase.invoke("SetPassword",$password) >> >> > $newuser.psbase.CommitChanges() >> >> > $ary = @() >> >> > $ary += $newuser.psbase.path >> >> > # Getting Group and Adding User >> >> > $g = [ADSI]("WinNT://$server/Administrators,group") >> >> > $g.psbase.invoke("add",$ary) >> >> > } >> >> > >> >> > function add-UsertoGroup{ >> >> > 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) >> >> > #if(!($g.psbase.invoke("isMember",$ary))) >> >> > {$g.psbase.invoke("add",$ary)} >> >> > #else {Write-Host "User already a Member" -ForegroundColor yellow} >> >> > # Checking Group for User >> >> > #if(!($g.psbase.invoke("IsMember",$ary))){Write-Host "User Add >> >> > Failed!" -ForegroundColor Red} >> >> > #else{Write-Host "User Added." -ForegroundColor green} >> >> > Write-Host "If no Exception... User Added" -ForegroundColor Green >> >> > } >> >> > >> >> > -- >> >> > Brandon Shell >> >> > --------------- >> >> > Stop by my blog some time ![]() >> >> > Blog: http://www.bsonposh.com/ >> >> > PSH Scripts Project: www.codeplex.com/psobject >> >> > -------------------------------------- >> >> > >> >> > "frank" <frank@discussions.microsoft.com> wrote in message >> >> > news:50ABD76E-C714-47A7-8032-4332023897C2@microsoft.com... >> >> >> Sorry for the repost but does any one know how to create a local >> >> >> user >> >> >> in powershecll >> >> > >> >> >> >> >> >> |
My System Specs![]() |
| | #8 (permalink) |
| Guest | Re: local user please ok it not geetting an error and I really sorry to bug you but nothing happens I type in ./user.ps1 just shows up back at ps prompt I try ./user.ps1 username password group server and evrything in between and nothing happens plase help "Brandon Shell" wrote: > Again.. same problem cut/paste is evil> > Just make sure any reference to -foregroundcolor is on the same line as > write-host. It is a parameter. > > This is the line I think is erroring > #if(!($g.psbase.invoke("IsMember",$ary))){Write-Host "User Add > Failed!" -ForegroundColor Red} > > This is just a comment so you can delete the whole line or at least make it > on one line > > -- > Brandon Shell > --------------- > Stop by my blog some time ![]() > Blog: http://www.bsonposh.com/ > PSH Scripts Project: www.codeplex.com/psobject > -------------------------------------- > > "frank" <frank@discussions.microsoft.com> wrote in message > news:667FD8FA-C74D-47FA-A117-83B8D9DF1B40@microsoft.com... > > different error now > > > > Incomplete string taken > > +F <<< ailed -foregroundcolor red > > > > I type in ./new.ps1 testuser 1233456 grouop server > > > > > > > > "Brandon Shell" wrote: > > > >> That looks like a cut/paste problem > >> > >> That should be on the same line as the write-host. > >> Write-Host > >> "----------------------------------------------" -ForegroundColor gray > >> should be > >> Write-Host "--------------------" -ForegroundColor gray > >> > >> > >> -- > >> Brandon Shell > >> --------------- > >> Stop by my blog some time ![]() > >> Blog: http://www.bsonposh.com/ > >> PSH Scripts Project: www.codeplex.com/psobject > >> -------------------------------------- > >> > >> "frank" <frank@discussions.microsoft.com> wrote in message > >> news:72106A5A-4FCC-4882-B587-3389D0E16D6D@microsoft.com... > >> >I get an error > >> > You must provide a value expersion on the right-hand side of -f > >> > operator > >> > "---------" > >> > -Fo <<<< reground color gray > >> > > >> > > >> > > >> > "Brandon Shell" wrote: > >> > > >> >> Disclaimer... this was before the valid -whatif push by the dev team. > >> >> > >> >> I STRONGLY recommend using Jeffrey's should-process script noted here: > >> >> http://blogs.msdn.com/powershell/default.aspx > >> >> > >> >> -- > >> >> Brandon Shell > >> >> --------------- > >> >> Stop by my blog some time ![]() > >> >> Blog: http://www.bsonposh.com/ > >> >> PSH Scripts Project: www.codeplex.com/psobject > >> >> -------------------------------------- > >> >> > >> >> "Brandon Shell" <tshell.mask@gmail.com> wrote in message > >> >> news:eh1l3LBYHHA.4440@TK2MSFTNGP03.phx.gbl... > >> >> > Some Functions I wrote for this... they all use WinNT instead of > >> >> > LDAP > >> >> > so > >> >> > you can run locally. > >> >> > > >> >> > function add-User{ > >> >> > Param([string]$user,[string]$password,[string]$server) > >> >> > If(!($server)){$server = get-content env:COMPUTERNAME} > >> >> > $tUser = [ADSI]("WinNT://$server,computer") > >> >> > $newuser = $tUser.psbase.children.add("$user","user") > >> >> > $newuser.psbase.invoke("SetPassword",$password) > >> >> > $newuser.psbase.CommitChanges() > >> >> > } > >> >> > > >> >> > function add-AdminUser{ > >> >> > Param([string]$user,[string]$password,[string]$server) > >> >> > If(!($server)){$server = get-content env:COMPUTERNAME} > >> >> > $tUser = [ADSI]("WinNT://$server,computer") > >> >> > $newuser = $tUser.psbase.children.add("$user","user") > >> >> > $newuser.psbase.invoke("SetPassword",$password) > >> >> > $newuser.psbase.CommitChanges() > >> >> > $ary = @() > >> >> > $ary += $newuser.psbase.path > >> >> > # Getting Group and Adding User > >> >> > $g = [ADSI]("WinNT://$server/Administrators,group") > >> >> > $g.psbase.invoke("add",$ary) > >> >> > } > >> >> > > >> >> > function add-UsertoGroup{ > >> >> > 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) > >> >> > #if(!($g.psbase.invoke("isMember",$ary))) > >> >> > {$g.psbase.invoke("add",$ary)} > >> >> > #else {Write-Host "User already a Member" -ForegroundColor yellow} > >> >> > # Checking Group for User > >> >> > #if(!($g.psbase.invoke("IsMember",$ary))){Write-Host "User Add > >> >> > Failed!" -ForegroundColor Red} > >> >> > #else{Write-Host "User Added." -ForegroundColor green} > >> >> > Write-Host "If no Exception... User Added" -ForegroundColor Green > >> >> > } > >> >> > > >> >> > -- > >> >> > Brandon Shell > >> >> > --------------- > >> >> > Stop by my blog some time ![]() > >> >> > Blog: http://www.bsonposh.com/ > >> >> > PSH Scripts Project: www.codeplex.com/psobject > >> >> > -------------------------------------- > >> >> > > >> >> > "frank" <frank@discussions.microsoft.com> wrote in message > >> >> > news:50ABD76E-C714-47A7-8032-4332023897C2@microsoft.com... > >> >> >> Sorry for the repost but does any one know how to create a local > >> >> >> user > >> >> >> in powershecll > >> >> > > >> >> > >> >> > >> > >> > > |
My System Specs![]() |
| | #9 (permalink) |
| Guest | Re: local user please Its no bother Sometimes I assume to much. To be clear these are functions not a scripts. If you type <. $pwd\user.ps1> this will load the function into your current scope. You can then reference the functions accordingly. Here are some examples: To Add a User. The . is very important PS> . $pwd\User.ps1 PS> add-User -User Jdoe -Password MyPassword -Server Server1 To Add to a group PS> add-UsertoGroup -user jdoe -group administrators -- Brandon Shell --------------- Stop by my blog some time ![]() Blog: http://www.bsonposh.com/ PSH Scripts Project: www.codeplex.com/psobject -------------------------------------- "frank" <frank@discussions.microsoft.com> wrote in message news 6029708-A684-4EA6-8E19-59EB63E9A081@microsoft.com...> ok it not geetting an error and I really sorry to bug you but nothing > happens > > I type in ./user.ps1 > just shows up back at ps prompt > I try ./user.ps1 username password group server > and evrything in between and nothing happens > > plase help > > > "Brandon Shell" wrote: > >> Again.. same problem cut/paste is evil>> >> Just make sure any reference to -foregroundcolor is on the same line as >> write-host. It is a parameter. >> >> This is the line I think is erroring >> #if(!($g.psbase.invoke("IsMember",$ary))){Write-Host "User Add >> Failed!" -ForegroundColor Red} >> >> This is just a comment so you can delete the whole line or at least make >> it >> on one line >> >> -- >> Brandon Shell >> --------------- >> Stop by my blog some time ![]() >> Blog: http://www.bsonposh.com/ >> PSH Scripts Project: www.codeplex.com/psobject >> -------------------------------------- >> >> "frank" <frank@discussions.microsoft.com> wrote in message >> news:667FD8FA-C74D-47FA-A117-83B8D9DF1B40@microsoft.com... >> > different error now >> > >> > Incomplete string taken >> > +F <<< ailed -foregroundcolor red >> > >> > I type in ./new.ps1 testuser 1233456 grouop server >> > >> > >> > >> > "Brandon Shell" wrote: >> > >> >> That looks like a cut/paste problem >> >> >> >> That should be on the same line as the write-host. >> >> Write-Host >> >> "----------------------------------------------" -ForegroundColor gray >> >> should be >> >> Write-Host "--------------------" -ForegroundColor gray >> >> >> >> >> >> -- >> >> Brandon Shell >> >> --------------- >> >> Stop by my blog some time ![]() >> >> Blog: http://www.bsonposh.com/ >> >> PSH Scripts Project: www.codeplex.com/psobject >> >> -------------------------------------- >> >> >> >> "frank" <frank@discussions.microsoft.com> wrote in message >> >> news:72106A5A-4FCC-4882-B587-3389D0E16D6D@microsoft.com... >> >> >I get an error >> >> > You must provide a value expersion on the right-hand side of -f >> >> > operator >> >> > "---------" >> >> > -Fo <<<< reground color gray >> >> > >> >> > >> >> > >> >> > "Brandon Shell" wrote: >> >> > >> >> >> Disclaimer... this was before the valid -whatif push by the dev >> >> >> team. >> >> >> >> >> >> I STRONGLY recommend using Jeffrey's should-process script noted >> >> >> here: >> >> >> http://blogs.msdn.com/powershell/default.aspx >> >> >> >> >> >> -- >> >> >> Brandon Shell >> >> >> --------------- >> >> >> Stop by my blog some time ![]() >> >> >> Blog: http://www.bsonposh.com/ >> >> >> PSH Scripts Project: www.codeplex.com/psobject >> >> >> -------------------------------------- >> >> >> >> >> >> "Brandon Shell" <tshell.mask@gmail.com> wrote in message >> >> >> news:eh1l3LBYHHA.4440@TK2MSFTNGP03.phx.gbl... >> >> >> > Some Functions I wrote for this... they all use WinNT instead of >> >> >> > LDAP >> >> >> > so >> >> >> > you can run locally. >> >> >> > >> >> >> > function add-User{ >> >> >> > Param([string]$user,[string]$password,[string]$server) >> >> >> > If(!($server)){$server = get-content env:COMPUTERNAME} >> >> >> > $tUser = [ADSI]("WinNT://$server,computer") >> >> >> > $newuser = $tUser.psbase.children.add("$user","user") >> >> >> > $newuser.psbase.invoke("SetPassword",$password) >> >> >> > $newuser.psbase.CommitChanges() >> >> >> > } >> >> >> > >> >> >> > function add-AdminUser{ >> >> >> > Param([string]$user,[string]$password,[string]$server) >> >> >> > If(!($server)){$server = get-content env:COMPUTERNAME} >> >> >> > $tUser = [ADSI]("WinNT://$server,computer") >> >> >> > $newuser = $tUser.psbase.children.add("$user","user") >> >> >> > $newuser.psbase.invoke("SetPassword",$password) >> >> >> > $newuser.psbase.CommitChanges() >> >> >> > $ary = @() >> >> >> > $ary += $newuser.psbase.path >> >> >> > # Getting Group and Adding User >> >> >> > $g = [ADSI]("WinNT://$server/Administrators,group") >> >> >> > $g.psbase.invoke("add",$ary) >> >> >> > } >> >> >> > >> >> >> > function add-UsertoGroup{ >> >> >> > 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) >> >> >> > #if(!($g.psbase.invoke("isMember",$ary))) >> >> >> > {$g.psbase.invoke("add",$ary)} >> >> >> > #else {Write-Host "User already a Member" -ForegroundColor >> >> >> > yellow} >> >> >> > # Checking Group for User >> >> >> > #if(!($g.psbase.invoke("IsMember",$ary))){Write-Host "User Add >> >> >> > Failed!" -ForegroundColor Red} >> >> >> > #else{Write-Host "User Added." -ForegroundColor green} >> >> >> > Write-Host "If no Exception... User Added" -ForegroundColor >> >> >> > Green >> >> >> > } >> >> >> > >> >> >> > -- >> >> >> > Brandon Shell >> >> >> > --------------- >> >> >> > Stop by my blog some time ![]() >> >> >> > Blog: http://www.bsonposh.com/ >> >> >> > PSH Scripts Project: www.codeplex.com/psobject >> >> >> > -------------------------------------- >> >> >> > >> >> >> > "frank" <frank@discussions.microsoft.com> wrote in message >> >> >> > news:50ABD76E-C714-47A7-8032-4332023897C2@microsoft.com... >> >> >> >> Sorry for the repost but does any one know how to create a local >> >> >> >> user >> >> >> >> in powershecll >> >> >> > >> >> >> >> >> >> >> >> >> >> >> >> |
My System Specs![]() |
| | #10 (permalink) |
| Guest | Re: local user please It almost perfect I need one more thing if possible I would like create a batch file user.bat so a user type user name password and it pass through to this script thanks "Brandon Shell" wrote: > Its no bother > > Sometimes I assume to much. To be clear these are functions not a scripts. > > If you type <. $pwd\user.ps1> this will load the function into your current > scope. > You can then reference the functions accordingly. Here are some examples: > > To Add a User. The . is very important > PS> . $pwd\User.ps1 > PS> add-User -User Jdoe -Password MyPassword -Server Server1 > > To Add to a group > PS> add-UsertoGroup -user jdoe -group administrators > > -- > Brandon Shell > --------------- > Stop by my blog some time ![]() > Blog: http://www.bsonposh.com/ > PSH Scripts Project: www.codeplex.com/psobject > -------------------------------------- > > "frank" <frank@discussions.microsoft.com> wrote in message > news 6029708-A684-4EA6-8E19-59EB63E9A081@microsoft.com...> > ok it not geetting an error and I really sorry to bug you but nothing > > happens > > > > I type in ./user.ps1 > > just shows up back at ps prompt > > I try ./user.ps1 username password group server > > and evrything in between and nothing happens > > > > plase help > > > > > > "Brandon Shell" wrote: > > > >> Again.. same problem cut/paste is evil> >> > >> Just make sure any reference to -foregroundcolor is on the same line as > >> write-host. It is a parameter. > >> > >> This is the line I think is erroring > >> #if(!($g.psbase.invoke("IsMember",$ary))){Write-Host "User Add > >> Failed!" -ForegroundColor Red} > >> > >> This is just a comment so you can delete the whole line or at least make > >> it > >> on one line > >> > >> -- > >> Brandon Shell > >> --------------- > >> Stop by my blog some time ![]() > >> Blog: http://www.bsonposh.com/ > >> PSH Scripts Project: www.codeplex.com/psobject > >> -------------------------------------- > >> > >> "frank" <frank@discussions.microsoft.com> wrote in message > >> news:667FD8FA-C74D-47FA-A117-83B8D9DF1B40@microsoft.com... > >> > different error now > >> > > >> > Incomplete string taken > >> > +F <<< ailed -foregroundcolor red > >> > > >> > I type in ./new.ps1 testuser 1233456 grouop server > >> > > >> > > >> > > >> > "Brandon Shell" wrote: > >> > > >> >> That looks like a cut/paste problem > >> >> > >> >> That should be on the same line as the write-host. > >> >> Write-Host > >> >> "----------------------------------------------" -ForegroundColor gray > >> >> should be > >> >> Write-Host "--------------------" -ForegroundColor gray > >> >> > >> >> > >> >> -- > >> >> Brandon Shell > >> >> --------------- > >> >> Stop by my blog some time ![]() > >> >> Blog: http://www.bsonposh.com/ > >> >> PSH Scripts Project: www.codeplex.com/psobject > >> >> -------------------------------------- > >> >> > >> >> "frank" <frank@discussions.microsoft.com> wrote in message > >> >> news:72106A5A-4FCC-4882-B587-3389D0E16D6D@microsoft.com... > >> >> >I get an error > >> >> > You must provide a value expersion on the right-hand side of -f > >> >> > operator > >> >> > "---------" > >> >> > -Fo <<<< reground color gray > >> >> > > >> >> > > >> >> > > >> >> > "Brandon Shell" wrote: > >> >> > > >> >> >> Disclaimer... this was before the valid -whatif push by the dev > >> >> >> team. > >> >> >> > >> >> >> I STRONGLY recommend using Jeffrey's should-process script noted > >> >> >> here: > >> >> >> http://blogs.msdn.com/powershell/default.aspx > >> >> >> > >> >> >> -- > >> >> >> Brandon Shell > >> >> >> --------------- > >> >> >> Stop by my blog some time ![]() > >> >> >> Blog: http://www.bsonposh.com/ > >> >> >> PSH Scripts Project: www.codeplex.com/psobject > >> >> >> -------------------------------------- > >> >> >> > >> >> >> "Brandon Shell" <tshell.mask@gmail.com> wrote in message > >> >> >> news:eh1l3LBYHHA.4440@TK2MSFTNGP03.phx.gbl... > >> >> >> > Some Functions I wrote for this... they all use WinNT instead of > >> >> >> > LDAP > >> >> >> > so > >> >> >> > you can run locally. > >> >> >> > > >> >> >> > function add-User{ > >> >> >> > Param([string]$user,[string]$password,[string]$server) > >> >> >> > If(!($server)){$server = get-content env:COMPUTERNAME} > >> >> >> > $tUser = [ADSI]("WinNT://$server,computer") > >> >> >> > $newuser = $tUser.psbase.children.add("$user","user") > >> >> >> > $newuser.psbase.invoke("SetPassword",$password) > >> >> >> > $newuser.psbase.CommitChanges() > >> >> >> > } > >> >> >> > > >> >> >> > function add-AdminUser{ > >> >> >> > Param([string]$user,[string]$password,[string]$server) > >> >> >> > If(!($server)){$server = get-content env:COMPUTERNAME} > >> >> >> > $tUser = [ADSI]("WinNT://$server,computer") > >> >> >> > $newuser = $tUser.psbase.children.add("$user","user") > >> >> >> > $newuser.psbase.invoke("SetPassword",$password) > >> >> >> > $newuser.psbase.CommitChanges() > >> >> >> > $ary = @() > >> >> >> > $ary += $newuser.psbase.path > >> >> >> > # Getting Group and Adding User > >> >> >> > $g = [ADSI]("WinNT://$server/Administrators,group") > >> >> >> > $g.psbase.invoke("add",$ary) > >> >> >> > } > >> >> >> > > >> >> >> > function add-UsertoGroup{ > >> >> >> > 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) > >> >> >> > #if(!($g.psbase.invoke("isMember",$ary))) > >> >> >> > {$g.psbase.invoke("add",$ary)} > >> >> >> > #else {Write-Host "User already a Member" -ForegroundColor > >> >> >> > yellow} > >> >> >> > # Checking Group for User > >> >> >> > #if(!($g.psbase.invoke("IsMember",$ary))){Write-Host "User Add > >> >> >> > Failed!" -ForegroundColor Red} > >> >> >> > #else{Write-Host "User Added." -ForegroundColor green} > >> >> >> > Write-Host "If no Exception... User Added" -ForegroundColor > >> >> >> > Green > >> >> >> > } > >> >> >> > > >> >> >> > -- > >> >> >> > Brandon Shell > >> >> >> > --------------- > >> >> >> > Stop by my blog some time ![]() > >> >> >> > Blog: http://www.bsonposh.com/ > >> >> >> > PSH Scripts Project: www.codeplex.com/psobject > >> >> >> > -------------------------------------- > >> >> >> > > >> >> >> > "frank" <frank@discussions.microsoft.com> wrote in message > >> >> >> > news:50ABD76E-C714-47A7-8032-4332023897C2@microsoft.com... > >> >> >> >> Sorry for the repost but does any one know how to create a local > >> >> >> >> user > >> >> >> >> in powershecll > >> >> >> > > >> >> >> > >> >> >> > >> >> > >> >> > >> > >> > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| renaming Local user account and Changing "Full Name" of same Local | VB Script | |||
| Local user profiles | Vista account administration | |||
| Logoff a local user | PowerShell | |||
| local user | PowerShell | |||
| Why \User\Me\AppData\Local contains so much? | Vista General | |||