Powershell 脚本从被排除的OU中提取用户
不确定是否有人能帮忙。我有一个脚本,从广告中提取所有不属于安全组的用户。此脚本使用$excludeOUs排除具有不需要在此组中的帐户的OU。然而,当我运行此程序时,它似乎会生成一些帐户,但它们所在的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'
# 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中。非常感谢你。