Issue with passing alternate credentials using powershell

Discussion in 'Scripting' started by Anatoli, Jul 29, 2007.

  1. Anatoli

    Anatoli Guest

    I'm using the below script and getting an error. See error below the script.
    I can't seem to find any information about this error. Can someone please
    help out?

    thanks,
    -----------------------------------------------------------------------------
    $strBase = "<LDAP://dc=nwtraders,dc=msft>"
    $strFilter = "(objectCategory=computer)"
    $strAttributes = "name"
    $strScope = "subtree"
    $strQuery = "$strBase;$strFilter;$strAttributes;$strScope"
    $strUser = "LondonAdmin"
    $strPwd = "Password1"

    $objConnection = New-Object -comObject "ADODB.Connection"
    $objConnection.provider = "ADsDSOObject"
    $objConnection.properties.item("user ID") = $strUser
    $objConnection.properties.item("Password") = $strPwd
    $objConnection.open("modifiedConnection")
    $objCommand = New-Object -comObject "ADODB.Command"

    $objCommand.ActiveConnection = $objConnection
    $objCommand.CommandText = $strQuery
    $objRecordSet = $objCommand.Execute()

    Do
    {
    $objRecordSet.Fields.item("name") |Select-Object Name,Value
    $objRecordSet.MoveNext()
    }
    Until ($objRecordSet.eof)

    $objConnection.Close()
    --------------------------------------------------------------------------------
    POWERSHELL EXCEPTION
    EXCEPTION TYPE:System.Management.Automation.SetValueInvocationException
    MESSAGE:Exception setting "Item": "Cannot find an overload for "Item" and
    the argument count: "1"."
    POSITION:
    At line:21 char:31
    + $objConnection.properties.item( <<<< "user ID") = $strUser
    --------------------------------------------------------------------------------
     
    Anatoli, Jul 29, 2007
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.