Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Trouble with ADSI and PSBASE - commitchanges() - very strange

Closed Thread
 
Thread Tools Display Modes
Old 05-26-2007   #1 (permalink)
Janssen
Guest


 

Trouble with ADSI and PSBASE - commitchanges() - very strange

Hello,

I'm tyring to use a Powershell script to disable computer accounts in Active
Directory, by changing the useraccount control bitwise operator from 4096 to
4098. I'm using the following code:

param ([string]$machine)

$searcher = new-object System.DirectoryServices.DirectorySearcher
$searcher.filter ="(&(CN=$machine))"
$computer = $searcher.Findone()
$adcomputerpath = $computer.Path
$mycomp = [adsi]$adcomputerpath
$mycomp.userAccountControl
$mycomp.userAccountControl = 4098
$mycomp.userAccountControl
$mycomp.psbase.CommitChanges()
$mycomp.userAccountControl

I have the $mycomp.userAccountControl in there to echo the current setting,
in an effort to troubleshoot. My problem is in the CommitChanges() line.
Though I have no idea why, It doesn't work if I paste the line in or run via
script, but it DOES run if I type $mycomp.psbase.C and hit <TAB> to make
"ommitChanges(" appear via tab completion, and then I put on the closing )

I can't come up with any ideas other than that it must be a bug.

Example when pasting it in:
$mycomp.userAccountControl
"ECHOED BACK": 4096
$mycomp.userAccountControl = 4098
$mycomp.userAccountControl
"ECHOED BACK": 4098
$mycomp.psbase.CommitChanges()
$mycomp.userAccountControl
"ECHOED BACK": 4096

Example when typing $mycomp.psbase.C and hitting <TAB>:
$mycomp.userAccountControl
"ECHOED BACK": 4096
$mycomp.userAccountControl = 4098
$mycomp.userAccountControl
"ECHOED BACK": 4098
$mycomp.psbase.CommitChanges()
$mycomp.userAccountControl
"ECHOED BACK": 4098

The whole purpose of this script is to be able to automate the process, so
hand entering and tab-completing isn't an option. Any ideas on this one? Am
I missing something really obvious?

Thanks in advance,

Janssen
Old 05-27-2007   #2 (permalink)
/\\/\\o\\/\\/ [MVP]
Guest


 

Re: Trouble with ADSI and PSBASE - commitchanges() - very strange

Can't confirm your problem, will look into it later if same happens here,
but I see you mix up the ADSI adapter ans PSbase, can you check what happens
if you use one of both methods ?

try Only using ADSI adapter :

$mycomp.userAccountControl = 4098
$mycomp.setInfo()

and try : Only DirectoryEntry (PsBase)

$mycomp.userAccountControl = 4098
$mycomp.psbase.CommitChanges()

Greetings /\/\o\/\/
http://thePowerShellGuy.com


"Janssen" <Janssen@discussions.microsoft.com> wrote in message
news:0E4F00A6-26B1-4DDE-B4EA-7C62E8FD7CCE@microsoft.com...
> Hello,
>
> I'm tyring to use a Powershell script to disable computer accounts in
> Active
> Directory, by changing the useraccount control bitwise operator from 4096
> to
> 4098. I'm using the following code:
>
> param ([string]$machine)
>
> $searcher = new-object System.DirectoryServices.DirectorySearcher
> $searcher.filter ="(&(CN=$machine))"
> $computer = $searcher.Findone()
> $adcomputerpath = $computer.Path
> $mycomp = [adsi]$adcomputerpath
> $mycomp.userAccountControl
> $mycomp.userAccountControl = 4098
> $mycomp.userAccountControl
> $mycomp.psbase.CommitChanges()
> $mycomp.userAccountControl
>
> I have the $mycomp.userAccountControl in there to echo the current
> setting,
> in an effort to troubleshoot. My problem is in the CommitChanges() line.
> Though I have no idea why, It doesn't work if I paste the line in or run
> via
> script, but it DOES run if I type $mycomp.psbase.C and hit <TAB> to make
> "ommitChanges(" appear via tab completion, and then I put on the closing )
>
> I can't come up with any ideas other than that it must be a bug.
>
> Example when pasting it in:
> $mycomp.userAccountControl
> "ECHOED BACK": 4096
> $mycomp.userAccountControl = 4098
> $mycomp.userAccountControl
> "ECHOED BACK": 4098
> $mycomp.psbase.CommitChanges()
> $mycomp.userAccountControl
> "ECHOED BACK": 4096
>
> Example when typing $mycomp.psbase.C and hitting <TAB>:
> $mycomp.userAccountControl
> "ECHOED BACK": 4096
> $mycomp.userAccountControl = 4098
> $mycomp.userAccountControl
> "ECHOED BACK": 4098
> $mycomp.psbase.CommitChanges()
> $mycomp.userAccountControl
> "ECHOED BACK": 4098
>
> The whole purpose of this script is to be able to automate the process, so
> hand entering and tab-completing isn't an option. Any ideas on this one?
> Am
> I missing something really obvious?
>
> Thanks in advance,
>
> Janssen


Old 05-27-2007   #3 (permalink)
/\\/\\o\\/\\/ [MVP]
Guest


 

Re: Trouble with ADSI and PSBASE - commitchanges() - very strange

again pasting error last example, only using psbase needed to be :

> $mycomp.psBase.userAccountControl = 4098
> $mycomp.psbase.CommitChanges()


"/\/\o\/\/ [MVP]" <mow001@hotmail.NoSpam> wrote in message
news:A6DDE3C6-56DD-4AE4-9F7D-01C0DF1D9A71@microsoft.com...
> Can't confirm your problem, will look into it later if same happens here,
> but I see you mix up the ADSI adapter ans PSbase, can you check what
> happens if you use one of both methods ?
>
> try Only using ADSI adapter :
>
> $mycomp.userAccountControl = 4098
> $mycomp.setInfo()
>
> and try : Only DirectoryEntry (PsBase)
>
> $mycomp.psBase.userAccountControl = 4098
> $mycomp.psbase.CommitChanges()
>
> Greetings /\/\o\/\/
> http://thePowerShellGuy.com
>
>
> "Janssen" <Janssen@discussions.microsoft.com> wrote in message
> news:0E4F00A6-26B1-4DDE-B4EA-7C62E8FD7CCE@microsoft.com...
>> Hello,
>>
>> I'm tyring to use a Powershell script to disable computer accounts in
>> Active
>> Directory, by changing the useraccount control bitwise operator from 4096
>> to
>> 4098. I'm using the following code:
>>
>> param ([string]$machine)
>>
>> $searcher = new-object System.DirectoryServices.DirectorySearcher
>> $searcher.filter ="(&(CN=$machine))"
>> $computer = $searcher.Findone()
>> $adcomputerpath = $computer.Path
>> $mycomp = [adsi]$adcomputerpath
>> $mycomp.userAccountControl
>> $mycomp.userAccountControl = 4098
>> $mycomp.userAccountControl
>> $mycomp.psbase.CommitChanges()
>> $mycomp.userAccountControl
>>
>> I have the $mycomp.userAccountControl in there to echo the current
>> setting,
>> in an effort to troubleshoot. My problem is in the CommitChanges() line.
>> Though I have no idea why, It doesn't work if I paste the line in or run
>> via
>> script, but it DOES run if I type $mycomp.psbase.C and hit <TAB> to make
>> "ommitChanges(" appear via tab completion, and then I put on the
>> closing )
>>
>> I can't come up with any ideas other than that it must be a bug.
>>
>> Example when pasting it in:
>> $mycomp.userAccountControl
>> "ECHOED BACK": 4096
>> $mycomp.userAccountControl = 4098
>> $mycomp.userAccountControl
>> "ECHOED BACK": 4098
>> $mycomp.psbase.CommitChanges()
>> $mycomp.userAccountControl
>> "ECHOED BACK": 4096
>>
>> Example when typing $mycomp.psbase.C and hitting <TAB>:
>> $mycomp.userAccountControl
>> "ECHOED BACK": 4096
>> $mycomp.userAccountControl = 4098
>> $mycomp.userAccountControl
>> "ECHOED BACK": 4098
>> $mycomp.psbase.CommitChanges()
>> $mycomp.userAccountControl
>> "ECHOED BACK": 4098
>>
>> The whole purpose of this script is to be able to automate the process,
>> so
>> hand entering and tab-completing isn't an option. Any ideas on this one?
>> Am
>> I missing something really obvious?
>>
>> Thanks in advance,
>>
>> Janssen

>


Old 05-27-2007   #4 (permalink)
RichS
Guest


 

RE: Trouble with ADSI and PSBASE - commitchanges() - very strange

Try using

$mycomp.userAccountControl = $mycomp.psbase.properties.useraccountcontrol[0]
-bor 2

to perform the disabling action. I have found working with user accounts
that this is best way. I can't remember the exact circumstance but I seem to
remember having similar problems to you when trying set the value directly


--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Janssen" wrote:

> Hello,
>
> I'm tyring to use a Powershell script to disable computer accounts in Active
> Directory, by changing the useraccount control bitwise operator from 4096 to
> 4098. I'm using the following code:
>
> param ([string]$machine)
>
> $searcher = new-object System.DirectoryServices.DirectorySearcher
> $searcher.filter ="(&(CN=$machine))"
> $computer = $searcher.Findone()
> $adcomputerpath = $computer.Path
> $mycomp = [adsi]$adcomputerpath
> $mycomp.userAccountControl
> $mycomp.userAccountControl = 4098
> $mycomp.userAccountControl
> $mycomp.psbase.CommitChanges()
> $mycomp.userAccountControl
>
> I have the $mycomp.userAccountControl in there to echo the current setting,
> in an effort to troubleshoot. My problem is in the CommitChanges() line.
> Though I have no idea why, It doesn't work if I paste the line in or run via
> script, but it DOES run if I type $mycomp.psbase.C and hit <TAB> to make
> "ommitChanges(" appear via tab completion, and then I put on the closing )
>
> I can't come up with any ideas other than that it must be a bug.
>
> Example when pasting it in:
> $mycomp.userAccountControl
> "ECHOED BACK": 4096
> $mycomp.userAccountControl = 4098
> $mycomp.userAccountControl
> "ECHOED BACK": 4098
> $mycomp.psbase.CommitChanges()
> $mycomp.userAccountControl
> "ECHOED BACK": 4096
>
> Example when typing $mycomp.psbase.C and hitting <TAB>:
> $mycomp.userAccountControl
> "ECHOED BACK": 4096
> $mycomp.userAccountControl = 4098
> $mycomp.userAccountControl
> "ECHOED BACK": 4098
> $mycomp.psbase.CommitChanges()
> $mycomp.userAccountControl
> "ECHOED BACK": 4098
>
> The whole purpose of this script is to be able to automate the process, so
> hand entering and tab-completing isn't an option. Any ideas on this one? Am
> I missing something really obvious?
>
> Thanks in advance,
>
> Janssen

Old 05-27-2007   #5 (permalink)
Janssen
Guest


 

Re: Trouble with ADSI and PSBASE - commitchanges() - very strange

That worked! When I run $mycomp | GM, I don't see setinfo(), (It only shows
properties) so I thought the only way to set it was psbase.commitchanges().
Thanks for the help!

Janssen

"/\\/\\o\\/\\/ [MVP]" wrote:

> try Only using ADSI adapter :
>
> $mycomp.userAccountControl = 4098
> $mycomp.setInfo()
>
> Greetings /\/\o\/\/
> http://thePowerShellGuy.com
>
>
> "Janssen" <Janssen@discussions.microsoft.com> wrote in message
> news:0E4F00A6-26B1-4DDE-B4EA-7C62E8FD7CCE@microsoft.com...
> > Hello,
> >
> > I'm tyring to use a Powershell script to disable computer accounts in
> > Active
> > Directory, by changing the useraccount control bitwise operator from 4096
> > to
> > 4098. I'm using the following code:
> >
> > param ([string]$machine)
> >
> > $searcher = new-object System.DirectoryServices.DirectorySearcher
> > $searcher.filter ="(&(CN=$machine))"
> > $computer = $searcher.Findone()
> > $adcomputerpath = $computer.Path
> > $mycomp = [adsi]$adcomputerpath
> > $mycomp.userAccountControl
> > $mycomp.userAccountControl = 4098
> > $mycomp.userAccountControl
> > $mycomp.psbase.CommitChanges()
> > $mycomp.userAccountControl
> >
> > I have the $mycomp.userAccountControl in there to echo the current
> > setting,
> > in an effort to troubleshoot. My problem is in the CommitChanges() line.
> > Though I have no idea why, It doesn't work if I paste the line in or run
> > via
> > script, but it DOES run if I type $mycomp.psbase.C and hit <TAB> to make
> > "ommitChanges(" appear via tab completion, and then I put on the closing )
> >
> > I can't come up with any ideas other than that it must be a bug.
> >
> > Example when pasting it in:
> > $mycomp.userAccountControl
> > "ECHOED BACK": 4096
> > $mycomp.userAccountControl = 4098
> > $mycomp.userAccountControl
> > "ECHOED BACK": 4098
> > $mycomp.psbase.CommitChanges()
> > $mycomp.userAccountControl
> > "ECHOED BACK": 4096
> >
> > Example when typing $mycomp.psbase.C and hitting <TAB>:
> > $mycomp.userAccountControl
> > "ECHOED BACK": 4096
> > $mycomp.userAccountControl = 4098
> > $mycomp.userAccountControl
> > "ECHOED BACK": 4098
> > $mycomp.psbase.CommitChanges()
> > $mycomp.userAccountControl
> > "ECHOED BACK": 4098
> >
> > The whole purpose of this script is to be able to automate the process, so
> > hand entering and tab-completing isn't an option. Any ideas on this one?
> > Am
> > I missing something really obvious?
> >
> > Thanks in advance,
> >
> > Janssen

>
>

Old 05-27-2007   #6 (permalink)
Janssen
Guest


 

RE: Trouble with ADSI and PSBASE - commitchanges() - very strange

By using my original code, and using the line below, this worked as well!
ADSI and Powershell is tricky sometimes.

"RichS" wrote:

> Try using
>
> $mycomp.userAccountControl = $mycomp.psbase.properties.useraccountcontrol[0]
> -bor 2
>
> to perform the disabling action. I have found working with user accounts
> that this is best way. I can't remember the exact circumstance but I seem to
> remember having similar problems to you when trying set the value directly
>
>
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog: http://richardsiddaway.spaces.live.com/
> PowerShell User Group: http://www.get-psuguk.org.uk
>
>
> "Janssen" wrote:
>
> > Hello,
> >
> > I'm tyring to use a Powershell script to disable computer accounts in Active
> > Directory, by changing the useraccount control bitwise operator from 4096 to
> > 4098. I'm using the following code:
> >
> > param ([string]$machine)
> >
> > $searcher = new-object System.DirectoryServices.DirectorySearcher
> > $searcher.filter ="(&(CN=$machine))"
> > $computer = $searcher.Findone()
> > $adcomputerpath = $computer.Path
> > $mycomp = [adsi]$adcomputerpath
> > $mycomp.userAccountControl
> > $mycomp.userAccountControl = 4098
> > $mycomp.userAccountControl
> > $mycomp.psbase.CommitChanges()
> > $mycomp.userAccountControl
> >
> > I have the $mycomp.userAccountControl in there to echo the current setting,
> > in an effort to troubleshoot. My problem is in the CommitChanges() line.
> > Though I have no idea why, It doesn't work if I paste the line in or run via
> > script, but it DOES run if I type $mycomp.psbase.C and hit <TAB> to make
> > "ommitChanges(" appear via tab completion, and then I put on the closing )
> >
> > I can't come up with any ideas other than that it must be a bug.
> >
> > Example when pasting it in:
> > $mycomp.userAccountControl
> > "ECHOED BACK": 4096
> > $mycomp.userAccountControl = 4098
> > $mycomp.userAccountControl
> > "ECHOED BACK": 4098
> > $mycomp.psbase.CommitChanges()
> > $mycomp.userAccountControl
> > "ECHOED BACK": 4096
> >
> > Example when typing $mycomp.psbase.C and hitting <TAB>:
> > $mycomp.userAccountControl
> > "ECHOED BACK": 4096
> > $mycomp.userAccountControl = 4098
> > $mycomp.userAccountControl
> > "ECHOED BACK": 4098
> > $mycomp.psbase.CommitChanges()
> > $mycomp.userAccountControl
> > "ECHOED BACK": 4098
> >
> > The whole purpose of this script is to be able to automate the process, so
> > hand entering and tab-completing isn't an option. Any ideas on this one? Am
> > I missing something really obvious?
> >
> > Thanks in advance,
> >
> > Janssen

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: still confused about "psbase & psobject", although read some pastposts. rmq PowerShell 0 2 Weeks Ago 09:19 PM
Is ADSI encrypted? jer PowerShell 3 01-18-2008 07:39 AM
psbase reference slow Bob Butler PowerShell 7 10-26-2007 12:03 PM
Info: What/Why/When of psbase Brandon Shell PowerShell 10 11-27-2006 02:54 PM
Invoking constructors directly from PSBase? Alex K. Angelopoulos [MVP] PowerShell 6 09-17-2006 12:00 AM








Vistax64.com 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 2005-2008

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 47 48 49 50