Wednesday, July 22, 2015

Fun With Powershell - Copy All Unique Files and Grab the Top X Lines

#change the prompt
function prompt { "Posh >" ; return " " }

#copy locally all unique file names
Get-ChildItem -Path \\server\ARC\Exp\AM\ -Recurse -Filter "*.txt" | ForEach-Object {"Copy " + $_.FullName  + " ""\\Dest\temp\ExperiantRegistration\" + $_.Name + "   " + $_.LastWriteTime + ".txt""" -replace ":", ""  -replace "/", "" >>  copyLocal.bat}

#Make the script file to Get just the top few lines
Get-ChildItem -Path C:\temp\ExperiantRegistration\ -Filter "*.txt" | ForEach-Object {"Get-Content " + """" + $_.FullName + """ -totalcount 3" > getHeaders.ps1}



No comments: