Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

CVS output from power-shell just outputting text length

$
0
0

i am writing a script to pull ad users who have not logged in within the last 90 days from a specific ou. that part works fine however when i try to get the users names and login times it just outputs as system string length what am i doing wrong

clear
$users = Get-ADUser -Filter 'enabled -eq $true' -SearchBase "ou=Administration - AD,OU=Regional Users,DC=pmh-mb,DC=ca"
$num=0
foreach ($user in $users)
{

    $un = $users.samaccountname
    $name = $user.Name
    $usr = get-aduser $user -properties lastlogontimestamp | select lastlogontimestamp
    $usr = $usr.lastlogontimestamp
    $TIME = $usr
    $DT = [DateTime]::FromFileTime($TIME)
    $date = "{0:yyyy/MM/dd}" -f (Get-Date).adddays(-90)
    if($dt -lt $date)
    {
        $num=$num+1
        $csv = "$num / $name / $DT"

        Export-Csv -Delimiter / -Path \\da3it162d\Share\accounts.csv  -Append -InputObject $csv
        Write-Host $csv
    }
    else {}
}



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>