【问题标题】:Extract domain name values from OU path powershell从 OU 路径 powershell 中提取域名值
【发布时间】:2022-10-21 21:16:30
【问题描述】:

我正在从 csv 中提取 OU 值并从中获取 DC 名称

    $TOD_Data= @(Import-Csv -Path "C:\data.csv")
    $OU = $TOD_Data.oupath
    $DC = ($OU -split '(?<![\\]),' | Where-Object { $_ -match '^DC=' }) -join ','

输出我能够提取如下值

DC=ab,DC=if,DC=csg,DC=net

但我需要像这样转换这个值

ab.if.csg.net

请让我知道我该怎么做

【问题讨论】:

    标签: powershell


    【解决方案1】:

    使用 Powershell 库中我的 PoshFunctions 模块中的函数 Split-DistinguisedName ,您可以通过以下方式获得答案:

    ((Split-DistinguishedName -DistinguishedName $dn -Token | Where { $_ -match '^DC=' } ) -replace '^DC=', '' ) -join '.'

    更多示例:

    $dnsample = 'CN=SampleUser,OU=users,DC=subdomain,DC=contosco,DC=com'
    ((Split-DistinguishedName -DistinguishedName $dnsample -Token | Where { $_ -match '^DC=' } ) -replace '^DC=', '' ) -join '.'
    
    subdomain.contosco.com
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-01
      • 1970-01-01
      • 2016-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多