PowerShell-新对象 : A Postional parameter cannot be found that accepts argument 'system.object[]'

标签 powershell

我对下面编写的代码有疑问。该代码应该做的是获取预定义用户的列表,然后尝试针对用户帐户测试 3 个密码。 (完整的代码已放在下面的答案中)我不断收到代码中的错误,如标题中所述。任何人都可以帮我解决这个问题吗?我总是来这里寻找答案,因为你们是最棒的!今天我无法弄清楚这一点。

              $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

最佳答案

您错过了 ArgumentList 上的 -。

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

关于PowerShell-新对象 : A Postional parameter cannot be found that accepts argument 'system.object[]' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32643022/

相关文章:

powershell - 在Powershell中将哈希表的输出格式化为输出到一行

bash - PowerShell 中的 IF 语句是否有简写形式?

powershell - 如何确保域 Controller 在线?

arrays - PowerShell 数组过滤器

powershell - 如何验证 PDF 文件是否为 "good"?

xml - 使用Powershell修改通过子属性迭代的XML父属性

powershell - Powershell/.net反射-GetMethod()查找常规方法,但找不到通用方法-为什么?

powershell - UTF8编码改变数据格式

html - 使用 powershell 从 HTML 网站抓取图像链接

sharepoint - 可以在 PowerShell 脚本中使用 RunWithElevatedPrivileges 吗?