通过CSV搜索Powershell以获取计算机名称 [英] Search powershell by CSV for Computer name
本文介绍了通过CSV搜索Powershell以获取计算机名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
已经负责搜索其中包含1000多个计算机名称的CSV文件的问题。我想知道是否有一种方法可以通过CSV文件使用Get-ADComputer搜索AD以获取计算机名称,并返回输出(如果它们存在于活动目录中)。到目前为止,除了手动完成之外,我无法提出其他任何建议。
Ive been tasked with the issue of searching a CSV file that has over 1000 computer names in it. I was wondering if there was a way to search AD with Get-ADComputer by the CSV file for the computer names and return the output if they exist in active directory. So far I haven't been able to come up with anything except of doing it manually.
推荐答案
Import-CSV MyCSV.CSV | Select-Object *,@{n='InAD';e={$n = $_.Name ; IF (Get-ADComputer -filter {Name -eq $n}) {$True} ELSE {$False}}} | Export-CSV MyNewCSV.CSV
在巨型行上。用包含计算机名称的任何列标题替换 $ _。Name中的名称。
On a mega-line. Replace "Name" in "$_.Name" with whatever column header contains the computer name.
(已编辑以添加说明和完整的cmdlet名称)。
(edited to add clarification and full cmdlet name).
这篇关于通过CSV搜索Powershell以获取计算机名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文