Hi All,
I've written the below script in powershell to get the both Name and last logon time for computer in a OU
$computers = Get-ADComputer -Filter * -SearchBase "OU=Servers,DC=contoso,DC=local" -Properties lastlogontimestamp
foreach ($computer in $computers){
$PCname = $computer.Name
$Lastlogon = $computer.lastlogontimestamp
if ($lastlogon.count -eq 0)
{ $time = [DateTime]0 }
else
{ $time = [datetime]$Lastlogon }
}
The problem I have is I want to export the outcome to a CSV in the format Name,Logontime can you please advise how I can change my script to do this thanks