在 CSV 中找到点并替换为在 Active Directory 组中找到的名称

巴哈

我有一个 TXT 文件并将其转换为 CSV。

现在我想要一个脚本:

  • 查看UserID列中是否有带点的名称(例如:)xyz.aaa其中带点的名称不是 UserID,而是 Group。
  • 然后它应该在 AD 中寻找它们。
  • 然后替换同一 CSV 文件中找到的名称。

在 TXT 文件中查找所有 CN 并在 CSV 文件中列出它们:

Select-String -Path $TXTFile  -Pattern 'CN=(.*?),' -AllMatches |
    Select-Object -Expand Matches |
    ForEach-Object { $_.Groups[1].Value } | 
    select @{L="UserID"; E={$_}} |
    Export-CSV $CSVFile1 -Delimiter ";" 

我尝试过但它不起作用,这绝对是错误的:

寻找.UserID其中是组列,然后寻找他们AD。替换 Groupnames 中的成员。

Get-ChildItem -Path $CSVFile1 | ForEach-Object {  
    (Get-Content $_.UserID).Replace('.','Get-ADGroupMember -identity "$_.UserID" -Recursive | Select Name') | Out-File $_.UserID
}
奥拉夫

我认为这样的事情应该可以解决问题

$ProcessedList = Import-Csv -Path $CSVFile1 -Delimiter ';' | 
    Select-Object -Property *,
    @{
        Name='ProcessedUserID';
        Expression={
            if ($_.UserID -match '\.') {
                (Get-ADGroupMember -Identity $_.UserID | 
                    Select-Object -ExpandProperty SamAccountName) -join ','
            }
            else {
                $_.UserID
            }
        }
    }
$ProcessedList
$ProcessedList | Export-CSV -Path 'Whatever' -NoTypeInformation -Delimiter ';'

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章