首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell AD-对象DistinguishedName属性

Powershell AD-对象DistinguishedName属性
EN

Stack Overflow用户
提问于 2016-06-23 20:49:32
回答 1查看 2K关注 0票数 0

我试图检查Get-Adcomputer返回的对象是否属于返回的DistinguishedName属性下的某个组。我似乎在网上找不到任何线索。这个属性包含几个不同的东西,我对OU值特别感兴趣。

代码语言:javascript
复制
$computer = Get-AdComputer "$computerName"
$computer.DistinguishedName

这将返回几个链接到OU和CN的属性,但我只对其中一个OU属性与“Server”匹配感兴趣。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-23 21:17:03

以下是一些你可以尝试的东西,如果你只是在寻找一张真假支票

代码语言:javascript
复制
$computer = Get-AdComputer "$computerName"
$dn = $computer.DistinguishedName

$dn.Split(',') -match '^ou=.*server'

或者你可以用这个来整条路

代码语言:javascript
复制
# split the distinguishedname into an array of CNs, OUs, etc.
$split = $dn.Split(',')

# setup match variable to signal that we found an object that matches what we are looking for.
$match = $false

# for each item in the array
($split | % {
    # only check this if we have not yet found a match
    # if this line is an OU whose name contains the word 'server'
    if (!$match -and $_ -match '^ou=.*server') {
        # set match to true because we found what we were looking for
        $match = $true
    }
    # if we have found a match, output this and all the rest of the objects to the pipeline
    if ($match) {
        $_
    }
# now we have an array starting at the OU we were looking for
# this join will put the pieces back together into a string so it looks right
}) -join ','

注意:如果您的任何对象的名称中都有逗号,则这可能无法工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38001602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档