首页 > 解决方案 > 从 csv 列表中获取广告中停用的计算机

问题描述

我试图找出哪些计算机被停用。为此,我在 csv 列表中提供了计算机名称。我只想输出已停用的计算机。这就是我所拥有的。不幸的是,我得到了所有停用的计算机。但我只想要 csv 中提供的名称

Import-CSV -Path "C:\pc_names" | Select -expand Name | Get-ADComputer -searchbase 'XXX' -Filter {(Enabled -eq $False)} -Properties Name, OperatingSystem | Export-CSV “C:\Temp\DisabledComps.CSV” -NoTypeInformation

标签: powershell

解决方案


很明显,这样的事情会忽略输入的内容并返回许多计算机。

'comp001' | get-adcomputer -filter 'Enabled -eq $False'

如果等到最后,会出现错误信息:

get-adcomputer : 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 pipeline input.
At line:1 char:13
+ 'comp001' | get-adcomputer -filter 'Enabled -eq $false'
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (comp001:String) [Get-ADComputer], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.ActiveDirectory.Management.Commands.GetADComputer

您可以在 foreach 循环中执行 get-adcomputer 并测试 Name :

$list = echo comp001 comp002 comp003
$list | % { get-adcomputer -filter 'Enabled -eq $False -and Name -eq $_' }

推荐阅读