Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - local user please

Reply
 
Old 03-06-2007   #1 (permalink)
frank


 
 

local user please

Sorry for the repost but does any one know how to create a local user
in powershecll

My System SpecsSystem Spec
Old 03-06-2007   #2 (permalink)
Brandon Shell


 
 

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 SpecsSystem Spec
Old 03-06-2007   #3 (permalink)
Brandon Shell


 
 

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 SpecsSystem Spec
Old 03-06-2007   #4 (permalink)
Brandon Shell


 
 

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 SpecsSystem Spec
Old 03-06-2007   #5 (permalink)
frank


 
 

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 SpecsSystem Spec
Old 03-06-2007   #6 (permalink)
frank


 
 

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 SpecsSystem Spec
Old 03-06-2007   #7 (permalink)
Brandon Shell


 
 

Re: local user please

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 SpecsSystem Spec
Old 03-06-2007   #8 (permalink)
frank


 
 

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 SpecsSystem Spec
Old 03-06-2007   #9 (permalink)
Brandon Shell


 
 

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
news6029708-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 SpecsSystem Spec
Old 03-06-2007   #10 (permalink)
frank


 
 

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
> news6029708-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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46