English 中文(简体)
条款中的权力分配
原标题:powershell wildcard array in the where clause

在有含有野心的阵列条款的地方,我与一个强食胜。 这里指我更大范围的指挥,

$excludedOUs = @("*OU=Loaners,*", "*OU=InStock,*", "*OU=Conference Room,*","*OU=Training,*") 
Get-ADComputer -SearchBase $targetOU -Property LastLogonDate,LastLogon | 
          Where-Object { $_.DistinguishedName -notin $excludedOUs } | Select-Object Name,DistinguishedName, @{l= LastLogonDate ;e={[DateTime]::FromFileTime($_.LastLogon)}}

我愿从目标单位退还一份机器清单。 OU,但我想将次级目标清单排除在目标之外。 OU. 我看到了多个员额来解释为什么出现失败(不需要“通知”中允许的焊卡,需要使用——类似和――不像带动卡等),我也看到了利用雷克斯解决问题的建议。 不幸的是,我的眼睛总是在经常表达的头目上 gl,我永远无法说明如何正确使用。 最后,我不想在阵列中使用野心。 如果不包括臭氧消耗潜能值阵列,

$excludedOUs = @("Loaners", "InStock", "Conference Room", "Training")

我倾向于这样做。 但是,我需要利用野生物,因为次红树只是分离财产的一部分。 此外,这些阵列并不总是仅限于这四个项目。 这可能是一个单一项目,或没有,或数十个。 我知道本组织内其他人将如何使用。 欢迎任何建议。

最佳回答

请注意,-in-contains及其被否定的变量仅能进行全值的比较,字面上equality

遗憾的是,<<t>t>t>,,或-match,

exreg http://www.un.org/Depts/DGACM/index_chinese.htm

# Define the exclusions as literal substrings, without "*"
$excludedOUs = 
  @("OU=Loaners,", "OU=InStock,", "OU=Conference Room,","OU=Training,")

# Join them with "|", to construct a single regex that matches
# any one of the substrings.
# In cases where the array elements contain regex metacharacters (see above), 
# use the following instead:
#   $regexExcludedOUs = $excludedOUs.ForEach({ [regex]::Escape($_) }) -join  | 
$regexExcludedOUs = $excludedOUs -join  | 

# Use the regex with -notmatch
Get-ADComputer -SearchBase $targetOU -Property LastLogonDate,LastLogon | 
  Where-Object { $_.DistinguishedName -notmatch $regexExcludedOUs } |
  Select-Object Name,DistinguishedName, @{l= LastLogonDate ;e={[DateTime]::FromFileTime($_.LastLogon)}}

[1] Two examples that in essence use the same technique as in the rest of the answer:
Whole-string matching: $regexes = fo+ , ba[r] ; $combinedRegex = ^({0})$ -f ($regexes -join | )
$combinedRegex then contains ^(fo+|ba[r])$ verbatim.
Prefix matching: $literalPrefixes = fo. , ba+ ; $combinedRegex = ^({0}) -f ($literalPrefixes.ForEach({ [regex]::Escape($_) }) -join | )
$combinedRegex then contains ^(fo.|ba+) verbatim.

问题回答

为了达到您的目标,即根据在尊贵的国歌中部分配对,将特定小口径排除在结果之外,你可以使用——而不是在您的“目标”条款中带有野心的经营者。 您可以修改您的法典。

1 D-1, 1 D-1, 1 P-5, 1 P-4, 1 P-3, 1 P-2, 1 P-2, 1 GS, 1 GS, 1 GS, 1 NS

Create an array of regex patterns based on $excludedOUs

(美元)

Join the patterns with "|" for regex "or" matching

(不包括Patterns-join 和)

Get-ADComputer -SearchBase $targetOU -Property LastLogonDate, LastLogon | Where-Object { $.DistinguishedName -notmatch $regexPattern } | Select-Object Name, DistinguishedName, @{l= LastLogonDate ;e={[DateTime]::FromFileTime($.LastLogon)}}

解释:

不包括的巴博列阵列由在每一部分不包括的美元中放弃任何特殊性质而设。 使用[条例]的术语: 这确保了这些扼杀物在常规表述中被作为字面扼杀处理。

可通过加入被排除在外的美元创造出价。 采用正常表达方式的代号的阵列。

The Where-Object clause then uses the -notmatch operator with the $regexPattern to exclude entries where the DistinguishedName matches any of the excluded patterns.

这样,你就可以将具体的副手排除在基于分离后部分配对的结果之外,而不需要阵列中的野心。





相关问题
Using JavaScript to get an LDAP multi-valued string attribute

I am trying to retrieve an object attribute in Active Directory that appears to be a multi-valued string (See canonicalName). After performing a search: var conn; conn.Open = Provider=ADsDSOObject; ...

Test "User Must Change Password" field in .Net 3.5

I m trying to perform some basic AD User managment tasks in C# using .Net 3.5 I ve got a System.DirectoryServices.AccountManagement.UserPrincipal object that contains the user details. I can call ...

SSIS Script Task connecting to AD

I have written a SSIS 2005 script task that connects to Active Directory and reads user accountnames to store in database. I was able to successfully test this on my local system by executing dtexec....

Update Full Name in Active Directory

I ve been thrust into the deep end with Active Directory (I m a web developer, go fig) I have a user that I ve changed first/last name on but the Full Name hasn t changed which is causing issues with ...

Authenticate against Active Directory/ISA from php [closed]

I have a complicated problem, exacerbated by the fact I don t really know where to start! Over the last few years, I ve developed a number of php web-based systems. When I built them, our network was ...