![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 |
| | #2 (permalink) |
| 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 |
| | #3 (permalink) |
| 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 > |
| | #4 (permalink) |
| 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 |
| | #5 (permalink) |
| 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 > > |
| | #6 (permalink) |
| 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 |
| |
| |
![]() |
| 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 |