Skip to content

Instantly share code, notes, and snippets.

@DarkAllien
Created March 28, 2017 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarkAllien/9bf5bc1bf55225a30ec54bf02401b5a7 to your computer and use it in GitHub Desktop.
Save DarkAllien/9bf5bc1bf55225a30ec54bf02401b5a7 to your computer and use it in GitHub Desktop.
$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