Hi all
I am totally new to scripting and have spent ages on writing the below.
It is all working apart from the date format.
When creating the .CSV files excel will convert 1/2 the dates UK and 1/2 USA no matter what format I choose.
Is there any way to add to the below script a UK format date? If someone can help and show me where to put the command it would be most helpful.
Normal 0 false false false EN-GB X-NONE X-NONE
Import-Module ActiveDirectory
function Get-ADUsersLastLogon()
{
$dcs = Get-ADDomainController -Filter {Name -like"*"}
$users = Get-ADUser -searchbase "OU=Users" -SearchScope OneLevel -Filter *
$time = 0
$exportFilePath ="C:\lastlogin.csv"
$columns = "name,username,datetime"
Out-File -filepath $exportFilePath -force -InputObject $columns
foreach($user in $users)
{
foreach($dc in $dcs)
{
$hostname = $dc.HostName
$currentUser = Get-ADUser $user.SamAccountName | Get-ADObject -Server $hostname -Properties lastLogon
if($currentUser.LastLogon -gt $time)
{
$time = $currentUser.LastLogon
}
}
$dt = [DateTime]::FromFileTime($time)
$row = $user.Name+","+$user.SamAccountName+","+$dt
Out-File -filepath $exportFilePath -append -noclobber -InputObject $row $time = 0 } } Get-ADUsersLastLogon