Created
March 28, 2017 11:19
-
-
Save DarkAllien/9bf5bc1bf55225a30ec54bf02401b5a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$lastData=(get-date).AddYears(-5) | |
$myFile = 'your_chosen_location' | |
$lastData = import-csv $myFile| select -ExpandProperty Timestamp -Last 1 | |
$data=Invoke-Sqlcmd -Query "select * from [SCCM_DATABASE(ex: CM_XXX)].dbo.v_AM_NormalizedDetectionHistory scep | |
where scep.timestamp > '${lastData}' | |
order by scep.Timestamp asc" -ServerInstance "SCCM_SQL_Server_FQDN" | |
if ($data) | |
{ | |
if ((Get-Item $myFile).length -gt 2500kb) | |
{ | |
$data | export-csv $myFile -NoTypeInformation | |
} | |
else | |
{ | |
$data | export-csv $myFile -Append -NoTypeInformation | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment