Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How to export out the date into the csv file?

$
0
0

Hi, I had been trying to export out the value of the date to csv file.

This is the  script:

$strADPath = 'LDAP://dc=test,dc=com'

function ConvertLargeIntegerToDate([object]$LargeInteger){

    try
    {
        $int64 = ConvertLargeIntegerToInt64 ($LargeInteger)   
     
        if ($int64 -gt 0)       
        {
          $retDate = [datetime]::fromfiletime($int64)
        }
        else
        {
            $retDate = $null
        }
        return $retDate
     }
     catch
     {
        return $null
     }

    
 }
 
$objSearch = New-Object DirectoryServices.DirectorySearcher

$objSearch.Filter = '(&(objectClass=user)(samaccountname=user1))'

$objSearch.SearchRoot = $strADPath

$objSearch.PageSize = 1000
$objSearch.SearchScope = "subtree" 
$objResults = $objSearch.Findall()


$dateAccountExpires = ConvertLargeIntegerToDate $objUser.accountexpires[0]
Write-Host "date Account expires: "  $dateAccountexpires

$objResults| ForEach-Object{                    
          $_.GetDirectoryEntry()
     } | 
Select-Object -Property @{Name="sAMaccountName";Expression={$_.sAMAccountName}},
@{Name="cn";Expression={$_.cn}},
@{Name="name";Expression={$_.name}},
@{Name="manager";Expression={$_.manager}},
@{Name="givenName";Expression={$_.givenName}},
@{Name="accountExpires";Expression={$_.dateAccountExpires}},
@{Name="department";Expression={$_.department}} |
Export-Csv -Path 'D:\test44.csv'

This is what I get in PowerShell ISE:

This is what I had get for the csv file for the expire date:



Viewing all articles
Browse latest Browse all 15028

Trending Articles



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