Kr0n1kK1ll3r
Kr0n1kK1ll3r

Reputation: 21

PowerShell - New-Object : A Postional parameter cannot be found that accepts argument 'system.object[]'

I am having issues with the code written below. What the code is supposed to do is grab a list of predefined users and then attempt to test 3 passwords against the users' accounts. (Full code has been placed below in the answers) I keep receiving errors within the code as stated above in the title. Could any one help me figure this out? I always come here looking for answers as you guys are the best! Today I am unable to figure this out.

              $cred = New-Object -TypeName System.Management.Automation.PSCredential Argumentlist $account, $entry
              foreach ($account in $accountfile){
                   try {
                         get-aduser “username” -credential $cred
                         $array += New-Object psobject -property @{'Account'=$account;'Password'=$entry}
                   }
                    catch { Write-Host "There was an issue"}
               }
        }
        $count++#increase counter
  }
  $newpass=$newpass[3..$newpass.count] #subtract the first 3 entries from the $newpass array
  $count= 0 #reset counter to zero

Upvotes: 2

Views: 8409

Answers (1)

Mike Shepard
Mike Shepard

Reputation: 18156

You missed the - on ArgumentList.

$cred = New-Object -TypeName System.Management.Automation.PSCredential -Argumentlist $account, $entry

Upvotes: 3

Related Questions