![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #11 (permalink) |
| | Re: local user please I dont believe there is need to make a batch file wrapper. If you take this text and add it to Add-User.Ps1 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() You can then run it like: PS> PathtoScript\Add-User.ps1 -user Jdoe -password HellO -server "ServerName" or from Command prompt c:\tmp> powershell -noprofile pathtoscript\add-user.ps1 -user jdoe2 -password hell0 -- 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:31C8D234-0035-4F62-BE36-B6B9047A347B@microsoft.com... > 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![]() |
| | #12 (permalink) |
| | Re: local user please The reason I want to create a batch so a user does need to go into power shell so a user will type in batchfile username password enter and it go and create the user and put them in the group It just easyer if can be setup that way any help will be appericated thanks again "Brandon Shell" wrote: > I dont believe there is need to make a batch file wrapper. > > If you take this text and add it to Add-User.Ps1 > > 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() > > > You can then run it like: > PS> PathtoScript\Add-User.ps1 -user Jdoe -password HellO -server > "ServerName" > or from Command prompt > c:\tmp> powershell -noprofile pathtoscript\add-user.ps1 -user > jdoe2 -password hell0 > > > -- > 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:31C8D234-0035-4F62-BE36-B6B9047A347B@microsoft.com... > > 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![]() |
| | #13 (permalink) |
| | Re: local user please If that is what you wish Batch File Starts here @echo Off powershell -noprofile pathtoscript\add-user.ps1 -user %1 -password %2 User calls like c:\AddUser.cmd Jdoe MyPass -- 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:29E03A33-DEAF-470C-8B15-36AAAE57A15A@microsoft.com... > The reason I want to create a batch so a user does need to go into power > shell > so a user will type in batchfile username password enter > and it go and create the user and put them in the group > > It just easyer if can be setup that way any help will be appericated > > > thanks again > > > "Brandon Shell" wrote: > >> I dont believe there is need to make a batch file wrapper. >> >> If you take this text and add it to Add-User.Ps1 >> >> 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() >> >> >> You can then run it like: >> PS> PathtoScript\Add-User.ps1 -user Jdoe -password HellO -server >> "ServerName" >> or from Command prompt >> c:\tmp> powershell -noprofile pathtoscript\add-user.ps1 -user >> jdoe2 -password hell0 >> >> >> -- >> 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:31C8D234-0035-4F62-BE36-B6B9047A347B@microsoft.com... >> > 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![]() |
| | #14 (permalink) |
| | Re: local user please Thank you for all your help "Brandon Shell" wrote: > If that is what you wish > > Batch File Starts here > > @echo Off > powershell -noprofile pathtoscript\add-user.ps1 -user %1 -password %2 > > User calls like > c:\AddUser.cmd Jdoe MyPass > > > -- > 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:29E03A33-DEAF-470C-8B15-36AAAE57A15A@microsoft.com... > > The reason I want to create a batch so a user does need to go into power > > shell > > so a user will type in batchfile username password enter > > and it go and create the user and put them in the group > > > > It just easyer if can be setup that way any help will be appericated > > > > > > thanks again > > > > > > "Brandon Shell" wrote: > > > >> I dont believe there is need to make a batch file wrapper. > >> > >> If you take this text and add it to Add-User.Ps1 > >> > >> 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() > >> > >> > >> You can then run it like: > >> PS> PathtoScript\Add-User.ps1 -user Jdoe -password HellO -server > >> "ServerName" > >> or from Command prompt > >> c:\tmp> powershell -noprofile pathtoscript\add-user.ps1 -user > >> jdoe2 -password hell0 > >> > >> > >> -- > >> 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:31C8D234-0035-4F62-BE36-B6B9047A347B@microsoft.com... > >> > 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 | |||