Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 脚本从被排除的OU中提取用户_Powershell - Fatal编程技术网

Powershell 脚本从被排除的OU中提取用户

Powershell 脚本从被排除的OU中提取用户,powershell,Powershell,不确定是否有人能帮忙。我有一个脚本,从广告中提取所有不属于安全组的用户。此脚本使用$excludeOUs排除具有不需要在此组中的帐户的OU。然而,当我运行此程序时,它似乎会生成一些帐户,但它们所在的OU似乎会在报告中显示它们。是否需要添加某种形式的命令来排除这些 # create a regex from an array of OUs to exclude by 'OR-ing' them with the pipe character $excludeOUs = ('OU=Exchange'

不确定是否有人能帮忙。我有一个脚本,从广告中提取所有不属于安全组的用户。此脚本使用$excludeOUs排除具有不需要在此组中的帐户的OU。然而,当我运行此程序时,它似乎会生成一些帐户,但它们所在的OU似乎会在报告中显示它们。是否需要添加某种形式的命令来排除这些

# create a regex from an array of OUs to exclude by 'OR-ing' them with the pipe character
$excludeOUs = ('OU=Exchange','OU=Support Accounts','OU=Terminated Users and Computers do not use',
               'OU=TerminatedEmployeesContractors','OU=TestAccounts','OU=Contractors and Consultants',
               'OU=MIS Users and Groups','OU=Service Accounts','OU=Security Groups','OU=Users',
               'OU=Testing','OU=Microsoft Exchange System Objects','OU=Microsoft Exchange Security Groups',
               'OU=CorpServiceAccounts','OU=Elevated','OU=***','OU=*** Assets','OU=Monitoring Mailboxes','OU=Users','OU=Q_Users','OU=Microsoft Exchange System Objects' | ForEach-Object {[Regex]::Escape($_)}) -join '|'

$ExportPath = 'c:\app\UsersNotinSG.csv'

# get a list of objects not having any of the excluded OUs in their DistinguishedName
# and at the same time output objects with properties 'User' and 'Groups'
 $grp=(Get-ADGroup 'SG_********').DistinguishedName
Get-ADUser -Filter { -not (memberof -eq $grp) -and (enabled -eq $true) } -Properties MemberOf | 
              Where-Object {$_.DistinguishedName -notmatch $excludeOUs} |
              Select-Object @{Name = 'User'; Expression = {$_.Name}},
                            @{name =  "OU";expression={$_.DistinguishedName.split(',')[1].split('=')[1]}}|
                            Export-Csv $ExportPath -NoTypeInformation

谢谢

HealthMailboxes*位于CN=监控邮箱中,而不是OU=–AdminOfThings

运营商需要regex。。。你给它一个数组,不是正则表达式或语句。请尝试改用
-in
中的。HealthMailboxes*位于
CN=监视邮箱
中,而不是
OU=
@AdminOfThings中。非常感谢你。