- #Windows powershell check for corrupted files how to#
- #Windows powershell check for corrupted files upgrade#
KS, that is all there is to using Windows PowerShell to detect files that have leading spaces. PS C:\a> gci -Recurse | % #end function Get-FilesWithLeadingSpacesĪfter I run the function, I go back into the Windows File Explorer to see if it worked. Nothing returns, which lends credence to my suspicion. To do this, I run the following Windows PowerShell code, which gets the length of the file name, and uses the Trim string method to remove excess spaces. Of course, the best way to check this is to use Windows PowerShell. This is shown in the image that follows.īut when I pressed ENTER, it seems that Windows Explorer stripped out the leading spaces. I opened Windows File Explorer, and created a new text file with 10 leading spaces. The first thing I decided to do was to create a file with a leading space in it. As a matter of a fact, I am not certain that until I read your email to I even knew that one could create a file with a leading space in it. To be honest, I do not think I have ever created a file with a leading space in the name-don’t know why I would want to do so. I am really saddened to hear about your problems at work. Wow! KS, I am sorry things have not been going so well for you recently. Microsoft Scripting Guy, Ed Wilson, is here. Well anyway, now I am “on notice” and I am really hoping you can help me. Of course, we did not replace the guy who was in charge of backups and who must have been the last planet to know about the software and the old tape array, but no one wants to hear about that. As luck would have it, the way we found out that the files were not getting backed up is that our CEO corrupted one of the files that had the leading space in it, and when we attempted to restore the file, we discovered the problem. But, for now, I need to figure out a way to detect files that are getting this leading space in the file name.
#Windows powershell check for corrupted files upgrade#
You might say we should upgrade our backup program, and that would be fine, except that our tape array is no longer supported and new backup programs do not have the correct driver. It works-except that it fails when it finds a file with a leading space in the file name. This is only part of the problem because our backup program is rather old. The reason is that for some reason we are getting files that have a leading space in the file name on one of our storage servers. We have a rather strange problem at work, and if I do not get to the end of it, I am afraid I might be looking for a new job. Hey, Scripting Guy! I am hoping that you can help me.
#Windows powershell check for corrupted files how to#
Summary: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to detect and to fix files that have leading spaces in the file name.