powershell - 从 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
解决方案
很明显,这样的事情会忽略输入的内容并返回许多计算机。
'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 $_' }
推荐阅读
- opc - 创建 OPC UA 信息模型
- reactjs - react-final-form 状态不包含空输入
- java - 没有任何关系的 LazyInitializationException - Spring Boot + Hibernate
- html - 如何使用引导程序在div中从左到中修复文本的位置
- android - 如何使用应用程序私有文件夹中的文件设置通知声音?
- firebase - Firebase:如果写入权限被拒绝,则阻止客户端回调执行
- java - 如何从另一个表中获取单个值作为字符串
- bash - 用上一行的内容替换文本
- android - 安卓 | 调试后手动安装apk失败
- ios - TableView 没有出现在我的容器中