Comments (6)

  1. Anonymous says:

    Hi Ed Wilson, the script works perfectly fine but when I run against -computer  Get-Content C:server.txt it gives me errors. I believe something to do with $ObjUser = [ADSI]"WinNT://$computer/$user" this entry.

    Is this possible for you to modify the script where its ask for input file for list of server names?

  2. mredwilson says:

    @Bradley Rigg This made my day. I forwarded it to the Scripting Wife, suggesting a bit more respect, she laughed. I forwarded it to the Scripting Manager, suggesting a title change, he laughed. So you brought a bit of cheer to three different people today — and that is not bad; not bad at all. Thank you so much for your comment!

  3. Bradley Rigg says:

    Thanks alot. You are a scripting GOD!

  4. mike says:

    Hey !!

    Thanks for the wonderful snippet .

    Can you help me to understand : why i am ended up in error while implementing as follows :

    C:ScriptsEnableDisableUser.ps1 : Unable to cast object of type ‘System.DirectoryServices.DirectoryEntry’ to type ‘System.Type’.

    And what should be done to avoid this error!!
    Thanks
    Mike

  5. JJ says:

    OK, I have done a lot to this script it now will prompt you for your inputs, will allow a txt list input file for running against multiple computers, and has custom error messages to catch most of the possible errors that can be made when entering input
    for the prompts. Enjoy!

    https://gallery.technet.microsoft.com/scriptcenter/EnableDisableUser-73bccd4e

  6. ohlssrog says:

    Im trying to disable the local administrator (renamed to NTAdmin) account on multiple servers. Have got help with a script.

    $user = “NTAdmin”
    $computer = “server01″,”server02”
    $EnableUser = 512
    $DisableUser = 2
    $ObjUser = [ADSI]”WinNT://$computer/$user”
    $objUser.userflags = $DisableUser # This set the disabled flag. To Enable the user change to $objUser.userflags = $EnableUser
    $objUser.setinfo() # The writes the changes to the user account

    But the execute get error that it cannot find the “,” name

    Exception setting “userflags”: “The following exception occurred while retrieving member “userflags”: “The network path was not found.
    “”
    At G:\PS_Scripts\disablelocaladmin.ps1:6 char:1
    + $objUser.userflags = $DisableUser # This set the disabled flag. To En …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting

    The following exception occurred while retrieving member “setinfo”: “The network path was not found.