Powershell Text File Output Only 1 Header

Hi,

We're trying to create a Powershell script that copies the Skype database file from multiple PCs to a backup location and then outputs the results to a text file. We're using PDQ Deploy to push the Powershell script to multiple PCs. The copy procedure and output to text file works fine, however, we'd like the text file to be formatted differently. I've attached 3 text files - log.txt shows the current output, log2.txt shows the desired output and backup_database.txt is the script. Could you advise how we can change the script to get this to format correctly?

Also, for some reason, the first letter of the username is sometimes removed as you can see with 'ewis' which should be 'Lewis' and we're not sure why?

Thanks
log.txt
log2.txt
backup_database.txt
ExcelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
The only way to get the format you want is to not write the headers at all.  So, on line 15 you could use the -HideTableHeaders parameter of Format-Table.  The other option is to not use Format-Table at all and just manually define the each line that you want to write.  For example:
$Files | ForEach { Write-Output "$($_.PathName)`t$($_.Modified)`t$($_.ComputerName)`t$($_.Owner)" } | Out-File "\\excelcare\backup\Skype Backups\Test\logs.txt" -Append

Open in new window


The reason for the missing letters of the username is because of this line.
Owner = (Get-Acl $File.FullName).Owner.Trim("EXCELCARE\")
The Trim() method works on a character array (it doesn't match a string).  The following command is equivalent.
Owner = (Get-Acl $File.FullName).Owner.Trim("EXCLAR\")
You could do the following instead.
Owner = ((Get-Acl $File.FullName).Owner) -replace "^EXCELCARE\\"

Open in new window

0
ExcelAuthor Commented:
Hi footech,

Thanks for your comment. When adding your suggestion into the script, the file that is produced isn't what we're after exactly. The formatting still isn't correct. The username issue is fixed with your suggestion so thanks very much for that. I've attached a sample of the output we receive after adding your suggestions. Hope you can help.

Thanks.
log.txt
0
footechCommented:
That's what I'm saying about manually defining each line.  You would have to change the command to exactly specify what you want.  Format-Table does it's own magic for determining column width, etc.  If you want to keep that use the parameter I mentioned earlier.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.