【问题标题】:Write results to file instead of writing to Active Directory live environment将结果写入文件而不是写入 Active Directory 实时环境
【发布时间】:2016-09-30 12:57:58
【问题描述】:

在生产环境中实际运行此脚本之前,我需要输出该脚本将执行的操作。有人可以帮忙吗?

它所做的只是更新用户对象中的 EmployeeID 属性。我的经理想要打印出所有 3500 名员工在 AD 中获得的价值,而无需实际写信给它。我希望这是有道理的。

我的 CSV 文件:

employeeid,Name
9089809890,ktest

脚本:

$stuff = Import-Csv c:\temp\finalexport_test.txt
$stuff

$empid = $stuff.employeeid
$userid = $stuff.name

foreach ($user in $userid) {
    Set-ADUser -Identity $user -EmployeeID $empid
    }

【问题讨论】:

    标签: powershell logging export-to-csv


    【解决方案1】:

    您可以将 Set-AdUser cmdlet 上的 -whatif 标志与 Transcript 一起使用:

    $stuff = Import-Csv c:\temp\finalexport_test.txt
    $stuff
    
    $empid = $stuff.employeeid
    $userid = $stuff.name
    
    foreach ($user in $userid) {
        Start-Transcript 'yourFile'
        Set-ADUser -Identity $user -EmployeeID $empid -whatif
        Stop-Transcript
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多