我有一个要求,以创建所有活动用户从公元CSV文件,包括直线经理属性,但是我需要直线经理 sAMAccountName赋
,而不是 CN
。这是我到目前为止有:
I've got a requirement to create a CSV file of all active users from AD including the line manager attribute, however I need the line managers sAMAccountName
, not the cn
. Here is what I have so far:
Get-ADUser -server server_ip -Filter { mail -like "*" -and ObjectClass -eq "user" } `
-SearchBase "OU=Active Users,DC=eu,DC=ad,DC=some_company,DC=com" `
-Properties objectGUID,displayName,office,division,department,employeeNumber,
employeeID,mobilePhone,officePhone,ipphone,title,givenName,surname,mail,
manager,sAMAccountName |
Export-CSV "EU_AD_Properties.csv"
这将返回所有我想要的数据,但给我的直线经理的 CN
,而不是 samacountname
。
This returns all the data I want, but gives me the line manager's cn
, not the samacountname
.
任何想法?
我已经试过这样:
Get-ADUser -server server_ip -Filter { mail -like "*" -and ObjectClass -eq "user" } `
-SearchBase "OU=Active Users,DC=eu,DC=ad,DC=some_company,DC=com" `
-Properties objectGUID,displayName,office,division,department,employeeNumber,
employeeID,mobilePhone,officePhone,ipphone,title,givenName,surname,mail,
@{Label="Manager";Expression={(Get-aduser -filter {sAMAccountName -eq $_.Manager}.sAMAaccountName)}},
sAMAccountName |
Export-CSV "EU_AD_Properties.csv"
不过这样的错误了。
However this errors out.
推荐答案
您不能创建参数的 -Properties
参数自定义属性,因为当前对象变量 $ _
不包含在该点的值(或至少不是你想要的值)。你需要做的,在一个选择
语句后面的管道,当 $ _
实际持有则需要在价值处理。您尝试创建自定义属性的方式将不会工作:
You can't create custom properties in arguments to the -Properties
parameter, because the current object variable $_
doesn't contain a value at that point (or at least not the value you want). You need to do that in a select
statement later in the pipeline, when $_
actually holds the value you need to process. The way you try to create the custom property won't work either:
@{Label="Manager";Expression={(Get-aduser -filter {sAMAccountName -eq $_.Manager}.sAMAaccountName)}}
过滤器脚本块不具有属性 sAMAccountName赋
。你真正想要做的就是让用户对象的经理CN并检索其 sAMAccountName赋
属性:
The filter scriptblock doesn't have an attribute sAMAccountName
. What you actually want to do is get the user object for the manager CN and retrieve its sAMAccountName
attribute:
@{Label='Manager';Expression={(Get-ADUser $_.Manager).sAMAccountName}}
另外,你不需要过滤对象类当量用户
,因为 GET-ADUser便有
将反正只返回用户对象。
Also, you don't need the filter ObjectClass -eq "user"
, because Get-ADUser
will return only user objects anyway.
所以,您的管道也许应该是这样的:
So your pipeline should probably look like this:
Get-ADUser -Server IP -Filter {mail -like "*"} -Properties * `
-SearchBase "OU=Active Users,DC=eu,DC=ad,DC=some_company,DC=com" |
select objectGUID, displayName, office, division, department, employeeNumber,
employeeID, mobilePhone, officePhone, ipphone, title, givenName, surname,
mail, @{Name='Manager';Expression={(Get-ADUser $_.Manager).sAMAccountName}},
sAMAccountName |
Export-CSV "EU_AD_Properties.csv"
相关推荐
最新文章