【问题标题】:Disable Computers with Powershell使用 Powershell 禁用计算机
【发布时间】:2018-09-25 06:30:36
【问题描述】:

我有 150 台计算机的列表,我想用 powershell 在活动目录中禁用。

所以我有一个包含计算机名和以下脚本的 csv 文件:

Import-Module ActiveDirectory

$computers = import-csv "C:\temp\test.csv"
foreach ($computer in $computers)
{
$computer | disable-adaccount
$computer | move-adobject -targetpath "OU=Disabled computers, DC=domain, DC=com"
}

出现以下错误:

Disable-ADAccount : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeli
ne input.

有人可以帮忙吗?

干杯

【问题讨论】:

    标签: windows active-directory


    【解决方案1】:

    尝试使用常规参数而不是管道:disable-adaccount $computer (如有必要,对另一个呼叫重复此操作)

    也可以在 Technet 上查看这个问题:Powershell script to disable AD account based on CSV file

    【讨论】:

      【解决方案2】:

      创建一个名为 disable.txt 的 txt 文件,并将您要禁用的计算机列表放在 C:\temp 位置

      运行此脚本:

      $Computer = Get-content c:\temp\disable.txt
      Foreach ($Computer in $computers) {
          Set-ADComputer -Identity $computer -Enabled $false
      }
      

      【讨论】:

        【解决方案3】:

        我知道这是一篇旧帖子,但我认为这是 Disable-ADAccount 期望输入属性而不是整个对象的类型不匹配。

        使用示例,我将 .DistinguishedName 添加到传递给 Disable-ADAccount 的项目中,并且它起作用了。不过,输入 csv 需要有可用于命令的 DistinguishedName。

        {
        Disable-ADAccount $StaleComputer.DistinguishedName
        Move-ADObject $StaleComputer.DistinguishedName -TargetPath "OU=Disabled Computers, DC=domain, DC=com"
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-01-13
          • 1970-01-01
          • 1970-01-01
          • 2021-07-07
          • 2018-11-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多