I often do automation work and one nice tool when we talk about SMS or SCCM data is SQLCMD.exe.
So how do I use it?
1. First I build a SQL query that gives me the data I want. I user query editor to find the right fields and then modify with functions etc.
2. I then normally store the query as a SQL view to make it more easy to call for.
3. Then I create a CMD file with SQLCMD.EXE command that calls for the view I created in step 2. SQLCMD has a lot of nice switches to format the data. See above!
4. When I get out the data in the correct format and into the right place (like to a file share where some non sms/sccm team can reach it) I create a scheduled task to run the CMD file with a user that both has SQL access and write access to the output folder.
Questions? Leace a comment!