adamchilcott

csvDump.ps1

Apr 4th, 2019
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ############################################################
  2. # Dump File Attributes for a Specific Folder Into a CSV File
  3. ############################################################
  4.  
  5. ################################
  6. # Specify Input/Output Variables
  7. ################################
  8.  
  9. ## $inputDirectory = "C:\MyFolder"
  10. ## $outputCSVFile = "C:\MyFolder\mycsvfilename.csv"
  11.  
  12. $inputDirectory = "$env:USERPROFILE\Desktop\MyFolder"
  13. $outputCSVFile = "$env:USERPROFILE\Desktop\mycsvfilename.csv"
  14.  
  15. ##################
  16. # Dump As Required
  17. ##################
  18.  
  19. Get-ChildItem -Recurse -File $inputDirectory | ForEach-Object {$_ | add-member -name "Owner" -membertype noteproperty -value (get-acl $_.fullname).owner -passthru} | Sort-Object fullname | Select FullName,CreationTime,LastWriteTime,Length,Owner | Export-Csv -Force -NoTypeInformation $outputCSVFile
  20.  
  21. #############
  22. # START NOTES
  23. #############
  24.  
  25. ## Reference:
  26. ## <https://heuristicandrew.blogspot.com/2014/09/write-directory-listing-to-csv-in.html>
  27.  
  28. # 2-clause license ("Simplified BSD License" or "FreeBSD License")
  29. #
  30. # Copyright © 2018, Adam Brian Chilcott
  31. # All rights reserved.
  32. #
  33. # Redistribution and use in source and binary forms, with or without
  34. # modification, are permitted provided that the following conditions are met:
  35. #
  36. # 1. Redistributions of source code must retain the above copyright notice, this
  37. # list of conditions and the following disclaimer.
  38. # 2. Redistributions in binary form must reproduce the above copyright notice,
  39. # this list of conditions and the following disclaimer in the documentation
  40. # and/or other materials provided with the distribution.
  41. #
  42. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  43. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  44. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  45. # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  46. # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  47. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  48. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  49. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  50. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  51. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  52. #
  53. # The views and conclusions contained in the software and documentation are those
  54. # of the authors and should not be interpreted as representing official policies,
  55. # either expressed or implied, of the FreeBSD Project.
  56.  
  57. ###########
  58. # END NOTES
  59. ###########
Add Comment
Please, Sign In to add comment