Powershell 如何从下面的脚本导出在AD中不正确或不可用的用户名和计算机名列表?
如何修改下面的脚本以导出Active Directory中不可用的servers.txt和Accounts.txt的列表 下面的脚本可以很好地从可用和联机的两个文件中导入列表,但我需要将错误或不可用帐户和计算机名的列表获取到单独的日志文件中,如: 分别失败的\u username.log和失败的\u computername.logPowershell 如何从下面的脚本导出在AD中不正确或不可用的用户名和计算机名列表?,powershell,Powershell,如何修改下面的脚本以导出Active Directory中不可用的servers.txt和Accounts.txt的列表 下面的脚本可以很好地从可用和联机的两个文件中导入列表,但我需要将错误或不可用帐户和计算机名的列表获取到单独的日志文件中,如: 分别失败的\u username.log和失败的\u computername.log $Servers = Get-Content "C:\Users\$env:username\desktop\servers.txt" | Wh
$Servers = Get-Content "C:\Users\$env:username\desktop\servers.txt" | Where-Object { ((Get-ADComputer -Filter "Name -eq '$($_)'" -Properties OperatingSystem).OperatingSystem -like '*Windows Server*') -and (Test-Connection -ComputerName $_ -Count 2 -Quiet) }
$Users = Get-Content "C:\Users\$env:username\desktop\Accounts.txt" | Where-Object { (Get-ADUser -Filter "SamAccountName -eq '$($_)'") }
ForEach ($Server in $Servers)
{
$ComputerName = $Server.Trim()
Write-Host "Processing $ComputerName" -ForegroundColor Green
ForEach ($Username in $Users)
{
$UserName = $User.Trim()
Write-Host "Processing $UserName" -ForegroundColor DarkGreen
}
}
我可以建议另一种方法吗?我认为将用户和计算机放在同一个列表中没有多大意义 我会这样做:我会收集如下列表中有关计算机的信息:
$ServerInputList =
Get-Content "C:\Users\$env:username\desktop\servers.txt"
foreach ($ComputerName in $ServerInputList) {
[PSCustomObject]@{
Name = $ComputerName
OS = (Get-ADComputer -Filter "Name -eq '$($ComputerName)'" -Properties OperatingSystem).OperatingSystem
Online = Test-Connection -ComputerName $ComputerName -Count 1 -Quiet
}
}
现在,您可以轻松筛选所需的计算机。
这同样适用于用户