$DomainControllers = "in1"
$Computers = @{}
$DomainControllers | ForEach-Object {
Get-QADComputer -SearchRoot "Developmuk/Countries/ID/Chi/Virines" -Service $_ -SizeLimit 0 -IncludedProperties LastLogon | `
Select-Object Name, DN, LastLogon | ForEach-Object {
If ($Computers.$($_.DN)) {
$Computers.$($_.DN) = $_ | Select-Object Name, DN, `
@{n='LastLogon';e={
If ($_.LastLogon -gt $Computers.$($_.DN).LastLogon) {
$_.LastLogon
} Else {
$Computers.$($_.DN).LastLogon
} }}
} Else {
$Computers.Add($_.DN, $_)
}
}
}
$Computers.Values | ForEach-Object {
$LastLogon = (New-TimeSpan $_.LastLogon).Days
If (Test-Connection $_.Name -Quiet -Count 1) {
$LastBootUpTime = (Get-WmiObject Win32_OperatingSystem -Computer $_.Name).LastBootUpTime
If ($LastBootUpTime -ne $Null) {
$LastBootUpTime = [Management.ManagementDateTimeConverter]::ToDateTime($LastBootUpTime)
$Online = [Math]::Round((New-TimeSpan $LastBootUpTime).TotalHours, 2)
}
} Else {
$Online = 0
}
$_ | Select-Object Name, @{n='LastLogon';e={ $LastLogon }}, @{n='Online';e={ $Online }}
} | Export-Csv "report.csv"
|