从Active Directory中的计算机属性中提取extensionAttribute [英] Extract extensionAttribute from Computer properties in Active Directory

查看:234
本文介绍了从Active Directory中的计算机属性中提取extensionAttribute的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Domain→ OU =客户端计算机→ OU =位置

每台计算机都有一个extensionAttribute1值.

我需要获取每台计算机的extensionAttribute1并导出到CSV文件.

我运行了下面的代码,但无法正确执行.尝试了很少的变化,但没有成功.

我先运行了这个(这里没有错误):

$Computers = Get-ADComputer -Filter * -SearchBase "OU=Location,OU=Client Computers,DC=ABC,DC=ABC1" -Properties *

然后我运行了这个

foreach ($Computer in $Computers) {
  Get-ADComputer $Computer -Filter * -Properties extensionAttribute5 |
    Export-Csv C:\computer_users.csv
}

,并出现以下错误:

Get-ADComputer:找不到可以接受的位置参数

我尝试使用括号,逗号,单引号,双引号和….只是想不通.

解决方案

Get-ADComputer $Computer -Filter * ...

相同

Get-ADComputer -Identity $Computer -Filter * ...

如果您查看文档,您会看到参数-Identity-Filter是互斥的.此外,您也不需要循环和第二个Get-ADComputer调用.只需从第一个Get-ADComputer调用中选择所需的属性,然后将结果通过管道传递到Export-Csv:

$ou = 'OU=Location,OU=Client Computers,DC=ABC,DC=ABC1'

Get-ADComputer -Filter * -SearchBase $ou -Properties extensionAttribute1 |
  Select-Object Name, extensionAttribute1, ... |
  Export-Csv 'C:\computer_users.csv' -NoType

Domain→OU=Client Computers→OU=Location

Each computers has an extensionAttribute1 value.

I need to get each computer's extensionAttribute1 and export to a CSV file.

I ran below code, but was unable to get it right. Tried few variation with no success.

I ran this first (no error here):

$Computers = Get-ADComputer -Filter * -SearchBase "OU=Location,OU=Client Computers,DC=ABC,DC=ABC1" -Properties *

Then I ran this:

foreach ($Computer in $Computers) {
  Get-ADComputer $Computer -Filter * -Properties extensionAttribute5 |
    Export-Csv C:\computer_users.csv
}

and got the following error:

Get-ADComputer : A positional parameter cannot be found that accepts argument

I tried with parenthesis, commas, single quotes, double quotes, … just can't figure it out.

解决方案

Get-ADComputer $Computer -Filter * ...

is the same as

Get-ADComputer -Identity $Computer -Filter * ...

If you take a look at the documentation you'll see that the parameters -Identity and -Filter are mutually exclusive. Besides, you don't need the loop and the second Get-ADComputer call anyway. Simply select the properties you want from your first Get-ADComputer call and pipe the result to Export-Csv:

$ou = 'OU=Location,OU=Client Computers,DC=ABC,DC=ABC1'

Get-ADComputer -Filter * -SearchBase $ou -Properties extensionAttribute1 |
  Select-Object Name, extensionAttribute1, ... |
  Export-Csv 'C:\computer_users.csv' -NoType

这篇关于从Active Directory中的计算机属性中提取extensionAttribute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆