0
我有一个包含名为MY-OU.txtPowershell的获得对用户登录OU在Active Directory
OU=offic-Computers,OU=comp-computers,DC=my,DC=company,DC=com
我可以得到该OU中的所有计算机列表的文本文件:
ForEach ($OU in Get-Content "C:\temp\MY-OU.txt")
{
Get-ADComputer -SearchBase $OU -Filter '*' | Select -Exp Name | Out-File -filepath "C:\temp\MY-OU-computers.txt"
}
,我可以得到当前登录用户从上面的代码的输出:
$content = Get-Content C:\temp\MY-OU-computers.txt
$output = foreach ($PC in $content) {Get-WmiObject –ComputerName $PC –Class Win32_ComputerSystem | Select-Object UserName}
$output | Out-File -filepath "C:\temp\CAD-OU-computers-users.txt"
如何这两部分结合起来,并得到当前在特定OU中登录的用户?
谢谢@詹姆斯C. – Eric