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?

    $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"
    $"user ID") = $strUser
    $"Password") = $strPwd
    $objCommand = New-Object -comObject "ADODB.Command"

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

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

    EXCEPTION TYPE:System.Management.Automation.SetValueInvocationException
    MESSAGE:Exception setting "Item": "Cannot find an overload for "Item" and
    the argument count: "1"."
    At line:21 char:31
    + $ <<<< "user ID") = $strUser
    Anatoli, Jul 29, 2007
    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.