繁体   English   中英

将PSObject正则表达式过滤后的结果与初始值名称组合

[英]Combine PSObject regex filtered results with initial value names

需要在我的广告中的USERS属性中搜索一些字符串数据。 我相信我已经迈出了第一步,并找到了它们,但是将结果合并到一个表中却遇到了一些麻烦-我需要确定用户的CN或Name(用来区分对象)。 以下是在任何字符串属性中搜索12至16个字符的代码:

$search = 'OU=root,DC=contoso,DC=com'
$props =    @(
            'CN',
            'City',
            'Company',
            'Department',
            'Description',
            'Division',
            'Fax',
            'HomeDirectory',
            'Homepage',
            'HomePhone',
            'Initials',
            'MobilePhone',
            'Office',
            'OfficePhone',
            'Organization',
            'OtherName',
            'POBox',
            'PostalCode',
            'State',
            'StreetAddress',
            'Title'
            )
Get-ADUser -Filter * -Properties * -SearchBase $search | Select $props |
%{$_.psobject.properties} | 
?{$_.Value -match "(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{12,16}"} | 
Format-Table @{N='CN';E={$_.CN}},Name,Value -AutoSize

这给了我表:

CN      Name        Value
____    ____        _____
        Description 2f565#124s$Dsa

我知道管道在末端没有固定CN。 我尝试使用foreach-object,但是在维护管道的情况下无法正确重写所有函数(例如psobject.properties)。 我需要类似的东西:

(User)CN                                        PropName        Value
CN=bradpitt,OU=Users,OU=root,DC=contoso,DC=com  Description     2f565#124s$Dsa

感谢LotPings,这是工作结果,可以搜索12到16个字符(正则表达式表示:至少-一个大写字母,一个小写字母,一个数字和一个特殊字符):

$search = 'OU=root,DC=contoso,DC=com'
$props =    @(
            'City',
            'Company',
            'Department',
            'Description',
            'Division',
            'Fax',
            'HomeDirectory',
            'Homepage',
            'HomePhone',
            'Initials',
            'MobilePhone',
            'Office',
            'OfficePhone',
            'Organization',
            'OtherName',
            'POBox',
            'PostalCode',
            'State',
            'StreetAddress',
            'Title'
            )
Get-ADUser -Filter * -Properties * -SearchBase $search | Select $props |
            ForEach-Object { $CN=$_.CN ; $_.psobject.properties} |
?{$_.Value -match "(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{12,16}"} | Format-Table @{N='CN';E={$CN}},Name,Value -AutoSize

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM