找出哪个组织单位是我域中的给定计算机列表
find out in which organizational unit are a given computer list in my domain
我有一个从我的域中选择的数百台计算机的列表。我想制作一份报告,显示其中 OU
都是他们。我发现这个 cmdlet 可以执行我需要的任务:
PS C:\Users\digiacomo.a-rti> Get-ADComputer "FIDS156041" -Properties DistinguishedName
但我想将包含我的计算机列表的(txt 或 csv)文件作为参数传递给它,而不是单台计算机 FIDS156041
,如果可能,将结果输出到另一个文件中其中包含两列:计算机名称及其 OU
。可能吗?我该怎么做?
非常感谢您的帮助!
这是一个例子:
#load a list of computers
$computerList = Get-Content "computerList.txt"
#results array
$results = @()
#for each computer
foreach($computerName in $computerList) {
#add result of command to results array
$results += Get-ADComputer $computerName -Properties Name, DistinguishedName | Select Name, DistinguishedName
}
#send results to CSV file
$results | Export-Csv "computerOUs.txt" -NoTypeInformation
我有一个从我的域中选择的数百台计算机的列表。我想制作一份报告,显示其中 OU
都是他们。我发现这个 cmdlet 可以执行我需要的任务:
PS C:\Users\digiacomo.a-rti> Get-ADComputer "FIDS156041" -Properties DistinguishedName
但我想将包含我的计算机列表的(txt 或 csv)文件作为参数传递给它,而不是单台计算机 FIDS156041
,如果可能,将结果输出到另一个文件中其中包含两列:计算机名称及其 OU
。可能吗?我该怎么做?
非常感谢您的帮助!
这是一个例子:
#load a list of computers
$computerList = Get-Content "computerList.txt"
#results array
$results = @()
#for each computer
foreach($computerName in $computerList) {
#add result of command to results array
$results += Get-ADComputer $computerName -Properties Name, DistinguishedName | Select Name, DistinguishedName
}
#send results to CSV file
$results | Export-Csv "computerOUs.txt" -NoTypeInformation