0
我前一段时间发布了一个问题,它得到的回答来完成我需要的东西 - Powershell & Get-ADUser - Split OU getting the 3rd, 4th and 5th elements from the endPowershell的&获取-ADUser便有 - 第2部分 - 把A和B一起
给出的答复
Get-ADUser -Filter * -Properties CanonicalName |
select -ExpandProperty CanonicalName |
ForEach-Object {
$Parts = $_.split('/')
$Object =
[PSCustomObject]@{
OU = $Parts[1]
Where = $Parts[2]
Type = 'N/A'
}
if ($Parts.count -ge 5)
{ $Object.Type = $Parts[3] }
$Object
}
现在我需要添加一些其他字段(名称,SAM帐户,电子邮件),并检查电子邮件*。这是我的第二个问题。
PowerShell的查询
$Headers= @{Label="OU Path";Expression={$_.CanonicalName}},
@{Label="Distinguished Name";Expression={$_.DistinguishedName}},
@{Label="Name";Expression={$_.DisplayName}},
@{Label="SAM Account";Expression={$_.SAMAccountName}},
@{Label="E-mail";Expression={$_.EmailAddress}},
Get-ADUser -Filter * -Properties
CanonicalName,DistinguishedName,DisplayName,
SamAccountName,EmailAddress | Select $Headers
我怎么可以结合它在我的上一个问题的答案,这个查询有以下输出提供?
另外我需要检查电子邮件,如果@ company.com那么“EType”= YES。
最终要达到的
OU Where Type Name SAM Email *EType
-----------------------------------------------------------------------------
DS AMS N/A Name1 brname1 [email protected] YES
DS TECHM N/A Name2 xsname2 [email protected] YES
Developers CH Agencies Name3 agname3 [email protected] NO
Developers CH Market Name4 chname4 [email protected] YES
Developers HK Agencies Name5 agname5 [email protected] NO
Developers HK Market Name6 hkname6 [email protected] YES
预先感谢您!
感谢,但是当我运行它,我只得到了不同的名称和SAM帐户 – JustQn4
嘛,canonicalname不ADUser便有财产,我认为你已经整理出了那部分内容。 – Santhos
您错过了Get-ADUser -Filter之后的-Properties。当我添加它的工作。非常感谢你! – JustQn4