我需要在此或Exchange代码中添加来自.csv文件的信息

发布于 2025-01-22 10:34:13 字数 552 浏览 0 评论 0原文

我有此链接,该链接将广告用户从OU通过来自.csv文件的信息更改。

在我的IT结构中,信息regiaodiretoria是必须包含在广告用户部门领域中的信息。

如何获取信息并在变量中重复使用?

`Department = $região + ", " + $Diretoria`




Import-Csv -Path  C:\Users\leonan.martins\Desktop\teste2.csv | ForEach-Object {
    $target = [string]::Format(
        "OU={0},OU={1},OU={2},DC=lab,DC=suporti,DC=local",
        $_.Regiao, $_.Diretoria, $_.Area
       
    )
    Get-ADUser $_.User | Move-ADObject -TargetPath $target
    Write-Host "OUs dos usuários ALTERADAS!"
}

I have this link that changes the AD user from OU through information coming from a .csv file.

In my IT structure, the information regiao and diretoria are the information that must also be contained in the Department field of the ad user.

How do I get the information and reuse it in the variables?

`Department = $região + ", " + $Diretoria`




Import-Csv -Path  C:\Users\leonan.martins\Desktop\teste2.csv | ForEach-Object {
    $target = [string]::Format(
        "OU={0},OU={1},OU={2},DC=lab,DC=suporti,DC=local",
        $_.Regiao, $_.Diretoria, $_.Area
       
    )
    Get-ADUser $_.User | Move-ADObject -TargetPath $target
    Write-Host "OUs dos usuários ALTERADAS!"
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

临走之时 2025-01-29 10:34:13

如果我正确理解,您正在想移动广告对象,但还设置它是decr验反之亦然。您可以使用-passTrhu返回正在使用的对象,该对象允许您在流管线中完成两个操作:

$ErrorActionPreference = 'Stop'

Import-Csv -Path C:\Users\leonan.martins\Desktop\teste2.csv | ForEach-Object {
    try {
        $target = [string]::Format(
            "OU={0},OU={1},OU={2},DC=lab,DC=suporti,DC=local",
            $_.Regiao, $_.Diretoria, $_.Area
        
        )

        Set-ADUser -Identity $_.User -Department ('{0},{1}' -f $_.Regiao, $_.Diretoria) -PassThru |
            Move-ADObject -TargetPath $target

        Write-Host "OUs dos usuários ALTERADAS!"
    }
    catch {
        Write-Warning $_.Exception.Message
    }
}

If I understand correctly, you're looking to move the AD Object but also, set it's Department attribute, in which case you could either first set the user's attribute and then move it to the target Organizational Unit or vice-versa. You can use -PassThru to return the object you are working with which allows you to complete both operations in a streamed pipeline:

$ErrorActionPreference = 'Stop'

Import-Csv -Path C:\Users\leonan.martins\Desktop\teste2.csv | ForEach-Object {
    try {
        $target = [string]::Format(
            "OU={0},OU={1},OU={2},DC=lab,DC=suporti,DC=local",
            $_.Regiao, $_.Diretoria, $_.Area
        
        )

        Set-ADUser -Identity $_.User -Department ('{0},{1}' -f $_.Regiao, $_.Diretoria) -PassThru |
            Move-ADObject -TargetPath $target

        Write-Host "OUs dos usuários ALTERADAS!"
    }
    catch {
        Write-Warning $_.Exception.Message
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文