How to use write-progress in get-filehash











up vote
1
down vote

favorite
1












i want to get progress while running the Get-Filehash command,
Here is a code i have but it is very slow and it takes more time to execute



Set-ExecutionPolicy Unrestricted -force
# Getting Filehash
Write-Host " "
Write-Host "----------------------------------------------------------------------"
Write-Host "Before Proceed, Copy the full Directory path or file path " -ForegroundColor White -BackgroundColor DarkMagenta
Write-Host "----------------------------------------------------------------------"
Write-Host " "
cd
cd .setup
$a=hostname
$output=$a+'hash.txt'
$file = Get-ChildItem -file (Read-Host "Enter Full Directory or File path") -Recurse
$filecount= $file.count
Foreach ($filecount in $file)
{
$i++
Write-Progress -activity "Processing file:- $filecount" -Status "MD5 CheckSum Progress file:- $i" -percentcomplete ($i/$file.count*100)
$file | Get-FileHash -Algorithm MD5 |Sort-Object path | Format-Table hash, Path -HideTableHeaders | Out-File $output
}
if (Test-Path $output) {
if((Get-Item $output).length -gt 0kb){
get-Content $output
Write-Host " "
Write-Host "CheckSum Completed Successfully " -ForegroundColor White -BackgroundColor Darkgreen
Write-Host 'Press any key to return to main menu...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
} else {
Write-Host " "
Write-Host "Error Occured" -ForegroundColor red
Write-Host " "
Write-Host "please check the file name or directory path "
Write-Host " "
Write-Host 'Press any key to return to main menu...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}
}


this code is working but very slow processing. please help to make the script faster with write-progress.



second method:-



$file = Get-ChildItem -file (Read-Host "Enter Full Directory or File path") -Recurse 
$filecount= $file.count
For($i = 0; $i -le $filecount; $i++) {
Write-Progress -activity "MD5 Check Processing " -Status "Progress file:- $i of $filecount" -percentcomplete ($i/$file.count*100)
$file | Get-FileHash -Algorithm MD5 | Sort-Object path | Format-Table hash, Path -HideTableHeaders -AutoSize | Out-File $output -Width 200
}









share|improve this question
























  • [1] your $filecount= line is doing NOTHING since you use that same $Var in the foreach that follows it. ///// [2] you are running the hash cmdlet on every file EVERY TIME the foreach loop iterates! the $file | stuff sends the entire list of files again, and again, and again ... [grin] ///// [3] the Write-Progress cmdlet is not at all fast. if all you want is a general indicator the what has been done, use a counter or just show the file names.
    – Lee_Dailey
    Nov 19 at 4:28










  • @Lee_Dailey, i added the counter now it looks little faster but if the files size is more it is taking more, please help me to edit the script i am a beginner in powershell
    – karhtik
    Nov 19 at 5:39












  • you are still running the hash cmdlet on each file multiple times. [grin] let me try some code ...
    – Lee_Dailey
    Nov 19 at 6:59










  • The Set-ExecutionPolicy in the beginning of your script makes no sense at all since the execution policy is evaluated before running a .PS1 file
    – bluuf
    Nov 19 at 10:02















up vote
1
down vote

favorite
1












i want to get progress while running the Get-Filehash command,
Here is a code i have but it is very slow and it takes more time to execute



Set-ExecutionPolicy Unrestricted -force
# Getting Filehash
Write-Host " "
Write-Host "----------------------------------------------------------------------"
Write-Host "Before Proceed, Copy the full Directory path or file path " -ForegroundColor White -BackgroundColor DarkMagenta
Write-Host "----------------------------------------------------------------------"
Write-Host " "
cd
cd .setup
$a=hostname
$output=$a+'hash.txt'
$file = Get-ChildItem -file (Read-Host "Enter Full Directory or File path") -Recurse
$filecount= $file.count
Foreach ($filecount in $file)
{
$i++
Write-Progress -activity "Processing file:- $filecount" -Status "MD5 CheckSum Progress file:- $i" -percentcomplete ($i/$file.count*100)
$file | Get-FileHash -Algorithm MD5 |Sort-Object path | Format-Table hash, Path -HideTableHeaders | Out-File $output
}
if (Test-Path $output) {
if((Get-Item $output).length -gt 0kb){
get-Content $output
Write-Host " "
Write-Host "CheckSum Completed Successfully " -ForegroundColor White -BackgroundColor Darkgreen
Write-Host 'Press any key to return to main menu...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
} else {
Write-Host " "
Write-Host "Error Occured" -ForegroundColor red
Write-Host " "
Write-Host "please check the file name or directory path "
Write-Host " "
Write-Host 'Press any key to return to main menu...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}
}


this code is working but very slow processing. please help to make the script faster with write-progress.



second method:-



$file = Get-ChildItem -file (Read-Host "Enter Full Directory or File path") -Recurse 
$filecount= $file.count
For($i = 0; $i -le $filecount; $i++) {
Write-Progress -activity "MD5 Check Processing " -Status "Progress file:- $i of $filecount" -percentcomplete ($i/$file.count*100)
$file | Get-FileHash -Algorithm MD5 | Sort-Object path | Format-Table hash, Path -HideTableHeaders -AutoSize | Out-File $output -Width 200
}









share|improve this question
























  • [1] your $filecount= line is doing NOTHING since you use that same $Var in the foreach that follows it. ///// [2] you are running the hash cmdlet on every file EVERY TIME the foreach loop iterates! the $file | stuff sends the entire list of files again, and again, and again ... [grin] ///// [3] the Write-Progress cmdlet is not at all fast. if all you want is a general indicator the what has been done, use a counter or just show the file names.
    – Lee_Dailey
    Nov 19 at 4:28










  • @Lee_Dailey, i added the counter now it looks little faster but if the files size is more it is taking more, please help me to edit the script i am a beginner in powershell
    – karhtik
    Nov 19 at 5:39












  • you are still running the hash cmdlet on each file multiple times. [grin] let me try some code ...
    – Lee_Dailey
    Nov 19 at 6:59










  • The Set-ExecutionPolicy in the beginning of your script makes no sense at all since the execution policy is evaluated before running a .PS1 file
    – bluuf
    Nov 19 at 10:02













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





i want to get progress while running the Get-Filehash command,
Here is a code i have but it is very slow and it takes more time to execute



Set-ExecutionPolicy Unrestricted -force
# Getting Filehash
Write-Host " "
Write-Host "----------------------------------------------------------------------"
Write-Host "Before Proceed, Copy the full Directory path or file path " -ForegroundColor White -BackgroundColor DarkMagenta
Write-Host "----------------------------------------------------------------------"
Write-Host " "
cd
cd .setup
$a=hostname
$output=$a+'hash.txt'
$file = Get-ChildItem -file (Read-Host "Enter Full Directory or File path") -Recurse
$filecount= $file.count
Foreach ($filecount in $file)
{
$i++
Write-Progress -activity "Processing file:- $filecount" -Status "MD5 CheckSum Progress file:- $i" -percentcomplete ($i/$file.count*100)
$file | Get-FileHash -Algorithm MD5 |Sort-Object path | Format-Table hash, Path -HideTableHeaders | Out-File $output
}
if (Test-Path $output) {
if((Get-Item $output).length -gt 0kb){
get-Content $output
Write-Host " "
Write-Host "CheckSum Completed Successfully " -ForegroundColor White -BackgroundColor Darkgreen
Write-Host 'Press any key to return to main menu...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
} else {
Write-Host " "
Write-Host "Error Occured" -ForegroundColor red
Write-Host " "
Write-Host "please check the file name or directory path "
Write-Host " "
Write-Host 'Press any key to return to main menu...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}
}


this code is working but very slow processing. please help to make the script faster with write-progress.



second method:-



$file = Get-ChildItem -file (Read-Host "Enter Full Directory or File path") -Recurse 
$filecount= $file.count
For($i = 0; $i -le $filecount; $i++) {
Write-Progress -activity "MD5 Check Processing " -Status "Progress file:- $i of $filecount" -percentcomplete ($i/$file.count*100)
$file | Get-FileHash -Algorithm MD5 | Sort-Object path | Format-Table hash, Path -HideTableHeaders -AutoSize | Out-File $output -Width 200
}









share|improve this question















i want to get progress while running the Get-Filehash command,
Here is a code i have but it is very slow and it takes more time to execute



Set-ExecutionPolicy Unrestricted -force
# Getting Filehash
Write-Host " "
Write-Host "----------------------------------------------------------------------"
Write-Host "Before Proceed, Copy the full Directory path or file path " -ForegroundColor White -BackgroundColor DarkMagenta
Write-Host "----------------------------------------------------------------------"
Write-Host " "
cd
cd .setup
$a=hostname
$output=$a+'hash.txt'
$file = Get-ChildItem -file (Read-Host "Enter Full Directory or File path") -Recurse
$filecount= $file.count
Foreach ($filecount in $file)
{
$i++
Write-Progress -activity "Processing file:- $filecount" -Status "MD5 CheckSum Progress file:- $i" -percentcomplete ($i/$file.count*100)
$file | Get-FileHash -Algorithm MD5 |Sort-Object path | Format-Table hash, Path -HideTableHeaders | Out-File $output
}
if (Test-Path $output) {
if((Get-Item $output).length -gt 0kb){
get-Content $output
Write-Host " "
Write-Host "CheckSum Completed Successfully " -ForegroundColor White -BackgroundColor Darkgreen
Write-Host 'Press any key to return to main menu...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
} else {
Write-Host " "
Write-Host "Error Occured" -ForegroundColor red
Write-Host " "
Write-Host "please check the file name or directory path "
Write-Host " "
Write-Host 'Press any key to return to main menu...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}
}


this code is working but very slow processing. please help to make the script faster with write-progress.



second method:-



$file = Get-ChildItem -file (Read-Host "Enter Full Directory or File path") -Recurse 
$filecount= $file.count
For($i = 0; $i -le $filecount; $i++) {
Write-Progress -activity "MD5 Check Processing " -Status "Progress file:- $i of $filecount" -percentcomplete ($i/$file.count*100)
$file | Get-FileHash -Algorithm MD5 | Sort-Object path | Format-Table hash, Path -HideTableHeaders -AutoSize | Out-File $output -Width 200
}






powershell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 5:40

























asked Nov 19 at 3:23









karhtik

11210




11210












  • [1] your $filecount= line is doing NOTHING since you use that same $Var in the foreach that follows it. ///// [2] you are running the hash cmdlet on every file EVERY TIME the foreach loop iterates! the $file | stuff sends the entire list of files again, and again, and again ... [grin] ///// [3] the Write-Progress cmdlet is not at all fast. if all you want is a general indicator the what has been done, use a counter or just show the file names.
    – Lee_Dailey
    Nov 19 at 4:28










  • @Lee_Dailey, i added the counter now it looks little faster but if the files size is more it is taking more, please help me to edit the script i am a beginner in powershell
    – karhtik
    Nov 19 at 5:39












  • you are still running the hash cmdlet on each file multiple times. [grin] let me try some code ...
    – Lee_Dailey
    Nov 19 at 6:59










  • The Set-ExecutionPolicy in the beginning of your script makes no sense at all since the execution policy is evaluated before running a .PS1 file
    – bluuf
    Nov 19 at 10:02


















  • [1] your $filecount= line is doing NOTHING since you use that same $Var in the foreach that follows it. ///// [2] you are running the hash cmdlet on every file EVERY TIME the foreach loop iterates! the $file | stuff sends the entire list of files again, and again, and again ... [grin] ///// [3] the Write-Progress cmdlet is not at all fast. if all you want is a general indicator the what has been done, use a counter or just show the file names.
    – Lee_Dailey
    Nov 19 at 4:28










  • @Lee_Dailey, i added the counter now it looks little faster but if the files size is more it is taking more, please help me to edit the script i am a beginner in powershell
    – karhtik
    Nov 19 at 5:39












  • you are still running the hash cmdlet on each file multiple times. [grin] let me try some code ...
    – Lee_Dailey
    Nov 19 at 6:59










  • The Set-ExecutionPolicy in the beginning of your script makes no sense at all since the execution policy is evaluated before running a .PS1 file
    – bluuf
    Nov 19 at 10:02
















[1] your $filecount= line is doing NOTHING since you use that same $Var in the foreach that follows it. ///// [2] you are running the hash cmdlet on every file EVERY TIME the foreach loop iterates! the $file | stuff sends the entire list of files again, and again, and again ... [grin] ///// [3] the Write-Progress cmdlet is not at all fast. if all you want is a general indicator the what has been done, use a counter or just show the file names.
– Lee_Dailey
Nov 19 at 4:28




[1] your $filecount= line is doing NOTHING since you use that same $Var in the foreach that follows it. ///// [2] you are running the hash cmdlet on every file EVERY TIME the foreach loop iterates! the $file | stuff sends the entire list of files again, and again, and again ... [grin] ///// [3] the Write-Progress cmdlet is not at all fast. if all you want is a general indicator the what has been done, use a counter or just show the file names.
– Lee_Dailey
Nov 19 at 4:28












@Lee_Dailey, i added the counter now it looks little faster but if the files size is more it is taking more, please help me to edit the script i am a beginner in powershell
– karhtik
Nov 19 at 5:39






@Lee_Dailey, i added the counter now it looks little faster but if the files size is more it is taking more, please help me to edit the script i am a beginner in powershell
– karhtik
Nov 19 at 5:39














you are still running the hash cmdlet on each file multiple times. [grin] let me try some code ...
– Lee_Dailey
Nov 19 at 6:59




you are still running the hash cmdlet on each file multiple times. [grin] let me try some code ...
– Lee_Dailey
Nov 19 at 6:59












The Set-ExecutionPolicy in the beginning of your script makes no sense at all since the execution policy is evaluated before running a .PS1 file
– bluuf
Nov 19 at 10:02




The Set-ExecutionPolicy in the beginning of your script makes no sense at all since the execution policy is evaluated before running a .PS1 file
– bluuf
Nov 19 at 10:02












3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










i just added the write-progress on the existing script, have a look



$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Progress -Activity "MD5 Check Processing :- $FL_Item " -Status "Processed $Counter " -PercentComplete (($Counter / $FileList.Count) * 100)
# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)
# send to text file





share|improve this answer





















  • This is working good with write-progress and also faster as like Write-Information. thanks
    – karhtik
    Nov 19 at 9:52


















up vote
1
down vote













your code is running the Get-FileHash cmdlet on the entire set of files once for every file. [grin] both your for and foreach versions have the entire file collection piped to the cmdlet for every loop.



here's a somewhat cleaner way to do the files just once each ...



# save the old Information preference
$OldInfoPref = $InformationPreference
# enable Information display
$InformationPreference = 'Continue'


$TargetDir = Read-Host 'Please enter the full path to the target Directory '

$FileList = Get-ChildItem -LiteralPath $TargetDir -Recurse -File

$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Information ('Processing file {0} of {1} ...' -f $Counter, $FileList.Count)

# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)

# on screen display
$Results

# send to CSV file
$Results |
Export-Csv -LiteralPath "$env:TEMPFileHashListing.csv" -NoTypeInformation

# restore Information preference
$InformationPreference = $OldInfoPref


partial on screen activity ...



Please enter the full path to the target Directory : c:temp
Processing file 1 of 566 ...
Processing file 2 of 566 ...
Processing file 3 of 566 ...
Processing file 4 of 566 ...
Processing file 5 of 566 ...
Processing file 6 of 566 ...
Processing file 7 of 566 ...
[*...snip...*]


partial on screen results ...



Hash                             Path
---- ----
D41D8CD98F00B204E9800998ECF8427E C:temp2018-11-17_22-00-00_-_TimeTest.txt
DD9972A59154D439B807217B40F7B569 C:tempau-descriptor-1.8.0_191-b12.xml
358D74CA3FB4A8DB01D2C1AB8BD7A0B5 C:tempCleanedVersion.log
33F2B09E2D9DFB732FA16B5F05A5A8D1 C:tempEnable1_WordList_File.txt
96B2DBFAE3F0353BF9FE5D87DD922C11 C:tempFunc_Get-Name.ps1
__Error__ C:tempFXSAPIDebugLogFile.txt
2E31A9B8BE6203D7636ED9E6A2B7D8CB C:tempGenre-List_2018-10-09.log
[*...snip...*]


partial CSV file content ...



"Hash","Path"
"D41D8CD98F00B204E9800998ECF8427E","C:temp2018-11-17_22-00-00_-_TimeTest.txt"
"DD9972A59154D439B807217B40F7B569","C:tempau-descriptor-1.8.0_191-b12.xml"
"358D74CA3FB4A8DB01D2C1AB8BD7A0B5","C:tempCleanedVersion.log"
"33F2B09E2D9DFB732FA16B5F05A5A8D1","C:tempEnable1_WordList_File.txt"
"5E6D32360C0A701B7A211C2AED5DD928","C:tempFileHashListing.csv"
"96B2DBFAE3F0353BF9FE5D87DD922C11","C:tempFunc_Get-Name.ps1"
"__Error__","C:tempFXSAPIDebugLogFile.txt"
"2E31A9B8BE6203D7636ED9E6A2B7D8CB","C:tempGenre-List_2018-10-09.log"
[*...snip...*]





share|improve this answer





















  • thanks for the time , the above script is working fine with Write-Information, also this requires Windows PowerShell 5.0,
    – karhtik
    Nov 19 at 9:42












  • @karhtik - you are very welcome! i enjoyed writing it. [grin] i didn't notice the PS version limitation. oops!
    – Lee_Dailey
    Nov 19 at 15:58


















up vote
1
down vote













I am posting the full script which is working good with write-progress



Set-ExecutionPolicy Unrestricted -force
# Getting Filehash
Write-Host " "
Write-Host "----------------------------------------------------------------------"
Write-Host "Before Proceed, Copy the full Directory path or file path " -ForegroundColor White -BackgroundColor DarkMagenta
Write-Host "----------------------------------------------------------------------"
Write-Host " "
cd
cd .script
$a=hostname
$output=$a+'hash.txt'
$TargetDir = Read-Host 'Please enter the full path to the target Directory '
$FileList = Get-ChildItem -LiteralPath $TargetDir -Recurse -File
$filecount= $FileList.count
$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Progress -Activity "MD5 Check Processing :- $FL_Item " -Status "Processed $Counter of $filecount" -PercentComplete (($Counter / $FileList.Count) * 100)
# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)
# send to text file
$Results |
Format-Table -HideTableHeaders -AutoSize | Out-File -FilePath $output -Width 200





share|improve this answer





















  • @Lee_Dailey thanks for the tips and script i used your idea to make this answer , T.Anand thanks for the time, the answer is combination of the both the script you guys provided
    – karhtik
    Nov 19 at 9:57










  • you are most welcome! glad to have helped a little ... [grin]
    – Lee_Dailey
    Nov 19 at 15:56











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53367889%2fhow-to-use-write-progress-in-get-filehash%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










i just added the write-progress on the existing script, have a look



$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Progress -Activity "MD5 Check Processing :- $FL_Item " -Status "Processed $Counter " -PercentComplete (($Counter / $FileList.Count) * 100)
# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)
# send to text file





share|improve this answer





















  • This is working good with write-progress and also faster as like Write-Information. thanks
    – karhtik
    Nov 19 at 9:52















up vote
1
down vote



accepted










i just added the write-progress on the existing script, have a look



$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Progress -Activity "MD5 Check Processing :- $FL_Item " -Status "Processed $Counter " -PercentComplete (($Counter / $FileList.Count) * 100)
# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)
# send to text file





share|improve this answer





















  • This is working good with write-progress and also faster as like Write-Information. thanks
    – karhtik
    Nov 19 at 9:52













up vote
1
down vote



accepted







up vote
1
down vote



accepted






i just added the write-progress on the existing script, have a look



$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Progress -Activity "MD5 Check Processing :- $FL_Item " -Status "Processed $Counter " -PercentComplete (($Counter / $FileList.Count) * 100)
# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)
# send to text file





share|improve this answer












i just added the write-progress on the existing script, have a look



$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Progress -Activity "MD5 Check Processing :- $FL_Item " -Status "Processed $Counter " -PercentComplete (($Counter / $FileList.Count) * 100)
# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)
# send to text file






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 9:47









T.Anand

10019




10019












  • This is working good with write-progress and also faster as like Write-Information. thanks
    – karhtik
    Nov 19 at 9:52


















  • This is working good with write-progress and also faster as like Write-Information. thanks
    – karhtik
    Nov 19 at 9:52
















This is working good with write-progress and also faster as like Write-Information. thanks
– karhtik
Nov 19 at 9:52




This is working good with write-progress and also faster as like Write-Information. thanks
– karhtik
Nov 19 at 9:52












up vote
1
down vote













your code is running the Get-FileHash cmdlet on the entire set of files once for every file. [grin] both your for and foreach versions have the entire file collection piped to the cmdlet for every loop.



here's a somewhat cleaner way to do the files just once each ...



# save the old Information preference
$OldInfoPref = $InformationPreference
# enable Information display
$InformationPreference = 'Continue'


$TargetDir = Read-Host 'Please enter the full path to the target Directory '

$FileList = Get-ChildItem -LiteralPath $TargetDir -Recurse -File

$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Information ('Processing file {0} of {1} ...' -f $Counter, $FileList.Count)

# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)

# on screen display
$Results

# send to CSV file
$Results |
Export-Csv -LiteralPath "$env:TEMPFileHashListing.csv" -NoTypeInformation

# restore Information preference
$InformationPreference = $OldInfoPref


partial on screen activity ...



Please enter the full path to the target Directory : c:temp
Processing file 1 of 566 ...
Processing file 2 of 566 ...
Processing file 3 of 566 ...
Processing file 4 of 566 ...
Processing file 5 of 566 ...
Processing file 6 of 566 ...
Processing file 7 of 566 ...
[*...snip...*]


partial on screen results ...



Hash                             Path
---- ----
D41D8CD98F00B204E9800998ECF8427E C:temp2018-11-17_22-00-00_-_TimeTest.txt
DD9972A59154D439B807217B40F7B569 C:tempau-descriptor-1.8.0_191-b12.xml
358D74CA3FB4A8DB01D2C1AB8BD7A0B5 C:tempCleanedVersion.log
33F2B09E2D9DFB732FA16B5F05A5A8D1 C:tempEnable1_WordList_File.txt
96B2DBFAE3F0353BF9FE5D87DD922C11 C:tempFunc_Get-Name.ps1
__Error__ C:tempFXSAPIDebugLogFile.txt
2E31A9B8BE6203D7636ED9E6A2B7D8CB C:tempGenre-List_2018-10-09.log
[*...snip...*]


partial CSV file content ...



"Hash","Path"
"D41D8CD98F00B204E9800998ECF8427E","C:temp2018-11-17_22-00-00_-_TimeTest.txt"
"DD9972A59154D439B807217B40F7B569","C:tempau-descriptor-1.8.0_191-b12.xml"
"358D74CA3FB4A8DB01D2C1AB8BD7A0B5","C:tempCleanedVersion.log"
"33F2B09E2D9DFB732FA16B5F05A5A8D1","C:tempEnable1_WordList_File.txt"
"5E6D32360C0A701B7A211C2AED5DD928","C:tempFileHashListing.csv"
"96B2DBFAE3F0353BF9FE5D87DD922C11","C:tempFunc_Get-Name.ps1"
"__Error__","C:tempFXSAPIDebugLogFile.txt"
"2E31A9B8BE6203D7636ED9E6A2B7D8CB","C:tempGenre-List_2018-10-09.log"
[*...snip...*]





share|improve this answer





















  • thanks for the time , the above script is working fine with Write-Information, also this requires Windows PowerShell 5.0,
    – karhtik
    Nov 19 at 9:42












  • @karhtik - you are very welcome! i enjoyed writing it. [grin] i didn't notice the PS version limitation. oops!
    – Lee_Dailey
    Nov 19 at 15:58















up vote
1
down vote













your code is running the Get-FileHash cmdlet on the entire set of files once for every file. [grin] both your for and foreach versions have the entire file collection piped to the cmdlet for every loop.



here's a somewhat cleaner way to do the files just once each ...



# save the old Information preference
$OldInfoPref = $InformationPreference
# enable Information display
$InformationPreference = 'Continue'


$TargetDir = Read-Host 'Please enter the full path to the target Directory '

$FileList = Get-ChildItem -LiteralPath $TargetDir -Recurse -File

$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Information ('Processing file {0} of {1} ...' -f $Counter, $FileList.Count)

# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)

# on screen display
$Results

# send to CSV file
$Results |
Export-Csv -LiteralPath "$env:TEMPFileHashListing.csv" -NoTypeInformation

# restore Information preference
$InformationPreference = $OldInfoPref


partial on screen activity ...



Please enter the full path to the target Directory : c:temp
Processing file 1 of 566 ...
Processing file 2 of 566 ...
Processing file 3 of 566 ...
Processing file 4 of 566 ...
Processing file 5 of 566 ...
Processing file 6 of 566 ...
Processing file 7 of 566 ...
[*...snip...*]


partial on screen results ...



Hash                             Path
---- ----
D41D8CD98F00B204E9800998ECF8427E C:temp2018-11-17_22-00-00_-_TimeTest.txt
DD9972A59154D439B807217B40F7B569 C:tempau-descriptor-1.8.0_191-b12.xml
358D74CA3FB4A8DB01D2C1AB8BD7A0B5 C:tempCleanedVersion.log
33F2B09E2D9DFB732FA16B5F05A5A8D1 C:tempEnable1_WordList_File.txt
96B2DBFAE3F0353BF9FE5D87DD922C11 C:tempFunc_Get-Name.ps1
__Error__ C:tempFXSAPIDebugLogFile.txt
2E31A9B8BE6203D7636ED9E6A2B7D8CB C:tempGenre-List_2018-10-09.log
[*...snip...*]


partial CSV file content ...



"Hash","Path"
"D41D8CD98F00B204E9800998ECF8427E","C:temp2018-11-17_22-00-00_-_TimeTest.txt"
"DD9972A59154D439B807217B40F7B569","C:tempau-descriptor-1.8.0_191-b12.xml"
"358D74CA3FB4A8DB01D2C1AB8BD7A0B5","C:tempCleanedVersion.log"
"33F2B09E2D9DFB732FA16B5F05A5A8D1","C:tempEnable1_WordList_File.txt"
"5E6D32360C0A701B7A211C2AED5DD928","C:tempFileHashListing.csv"
"96B2DBFAE3F0353BF9FE5D87DD922C11","C:tempFunc_Get-Name.ps1"
"__Error__","C:tempFXSAPIDebugLogFile.txt"
"2E31A9B8BE6203D7636ED9E6A2B7D8CB","C:tempGenre-List_2018-10-09.log"
[*...snip...*]





share|improve this answer





















  • thanks for the time , the above script is working fine with Write-Information, also this requires Windows PowerShell 5.0,
    – karhtik
    Nov 19 at 9:42












  • @karhtik - you are very welcome! i enjoyed writing it. [grin] i didn't notice the PS version limitation. oops!
    – Lee_Dailey
    Nov 19 at 15:58













up vote
1
down vote










up vote
1
down vote









your code is running the Get-FileHash cmdlet on the entire set of files once for every file. [grin] both your for and foreach versions have the entire file collection piped to the cmdlet for every loop.



here's a somewhat cleaner way to do the files just once each ...



# save the old Information preference
$OldInfoPref = $InformationPreference
# enable Information display
$InformationPreference = 'Continue'


$TargetDir = Read-Host 'Please enter the full path to the target Directory '

$FileList = Get-ChildItem -LiteralPath $TargetDir -Recurse -File

$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Information ('Processing file {0} of {1} ...' -f $Counter, $FileList.Count)

# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)

# on screen display
$Results

# send to CSV file
$Results |
Export-Csv -LiteralPath "$env:TEMPFileHashListing.csv" -NoTypeInformation

# restore Information preference
$InformationPreference = $OldInfoPref


partial on screen activity ...



Please enter the full path to the target Directory : c:temp
Processing file 1 of 566 ...
Processing file 2 of 566 ...
Processing file 3 of 566 ...
Processing file 4 of 566 ...
Processing file 5 of 566 ...
Processing file 6 of 566 ...
Processing file 7 of 566 ...
[*...snip...*]


partial on screen results ...



Hash                             Path
---- ----
D41D8CD98F00B204E9800998ECF8427E C:temp2018-11-17_22-00-00_-_TimeTest.txt
DD9972A59154D439B807217B40F7B569 C:tempau-descriptor-1.8.0_191-b12.xml
358D74CA3FB4A8DB01D2C1AB8BD7A0B5 C:tempCleanedVersion.log
33F2B09E2D9DFB732FA16B5F05A5A8D1 C:tempEnable1_WordList_File.txt
96B2DBFAE3F0353BF9FE5D87DD922C11 C:tempFunc_Get-Name.ps1
__Error__ C:tempFXSAPIDebugLogFile.txt
2E31A9B8BE6203D7636ED9E6A2B7D8CB C:tempGenre-List_2018-10-09.log
[*...snip...*]


partial CSV file content ...



"Hash","Path"
"D41D8CD98F00B204E9800998ECF8427E","C:temp2018-11-17_22-00-00_-_TimeTest.txt"
"DD9972A59154D439B807217B40F7B569","C:tempau-descriptor-1.8.0_191-b12.xml"
"358D74CA3FB4A8DB01D2C1AB8BD7A0B5","C:tempCleanedVersion.log"
"33F2B09E2D9DFB732FA16B5F05A5A8D1","C:tempEnable1_WordList_File.txt"
"5E6D32360C0A701B7A211C2AED5DD928","C:tempFileHashListing.csv"
"96B2DBFAE3F0353BF9FE5D87DD922C11","C:tempFunc_Get-Name.ps1"
"__Error__","C:tempFXSAPIDebugLogFile.txt"
"2E31A9B8BE6203D7636ED9E6A2B7D8CB","C:tempGenre-List_2018-10-09.log"
[*...snip...*]





share|improve this answer












your code is running the Get-FileHash cmdlet on the entire set of files once for every file. [grin] both your for and foreach versions have the entire file collection piped to the cmdlet for every loop.



here's a somewhat cleaner way to do the files just once each ...



# save the old Information preference
$OldInfoPref = $InformationPreference
# enable Information display
$InformationPreference = 'Continue'


$TargetDir = Read-Host 'Please enter the full path to the target Directory '

$FileList = Get-ChildItem -LiteralPath $TargetDir -Recurse -File

$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Information ('Processing file {0} of {1} ...' -f $Counter, $FileList.Count)

# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)

# on screen display
$Results

# send to CSV file
$Results |
Export-Csv -LiteralPath "$env:TEMPFileHashListing.csv" -NoTypeInformation

# restore Information preference
$InformationPreference = $OldInfoPref


partial on screen activity ...



Please enter the full path to the target Directory : c:temp
Processing file 1 of 566 ...
Processing file 2 of 566 ...
Processing file 3 of 566 ...
Processing file 4 of 566 ...
Processing file 5 of 566 ...
Processing file 6 of 566 ...
Processing file 7 of 566 ...
[*...snip...*]


partial on screen results ...



Hash                             Path
---- ----
D41D8CD98F00B204E9800998ECF8427E C:temp2018-11-17_22-00-00_-_TimeTest.txt
DD9972A59154D439B807217B40F7B569 C:tempau-descriptor-1.8.0_191-b12.xml
358D74CA3FB4A8DB01D2C1AB8BD7A0B5 C:tempCleanedVersion.log
33F2B09E2D9DFB732FA16B5F05A5A8D1 C:tempEnable1_WordList_File.txt
96B2DBFAE3F0353BF9FE5D87DD922C11 C:tempFunc_Get-Name.ps1
__Error__ C:tempFXSAPIDebugLogFile.txt
2E31A9B8BE6203D7636ED9E6A2B7D8CB C:tempGenre-List_2018-10-09.log
[*...snip...*]


partial CSV file content ...



"Hash","Path"
"D41D8CD98F00B204E9800998ECF8427E","C:temp2018-11-17_22-00-00_-_TimeTest.txt"
"DD9972A59154D439B807217B40F7B569","C:tempau-descriptor-1.8.0_191-b12.xml"
"358D74CA3FB4A8DB01D2C1AB8BD7A0B5","C:tempCleanedVersion.log"
"33F2B09E2D9DFB732FA16B5F05A5A8D1","C:tempEnable1_WordList_File.txt"
"5E6D32360C0A701B7A211C2AED5DD928","C:tempFileHashListing.csv"
"96B2DBFAE3F0353BF9FE5D87DD922C11","C:tempFunc_Get-Name.ps1"
"__Error__","C:tempFXSAPIDebugLogFile.txt"
"2E31A9B8BE6203D7636ED9E6A2B7D8CB","C:tempGenre-List_2018-10-09.log"
[*...snip...*]






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 7:08









Lee_Dailey

1,01266




1,01266












  • thanks for the time , the above script is working fine with Write-Information, also this requires Windows PowerShell 5.0,
    – karhtik
    Nov 19 at 9:42












  • @karhtik - you are very welcome! i enjoyed writing it. [grin] i didn't notice the PS version limitation. oops!
    – Lee_Dailey
    Nov 19 at 15:58


















  • thanks for the time , the above script is working fine with Write-Information, also this requires Windows PowerShell 5.0,
    – karhtik
    Nov 19 at 9:42












  • @karhtik - you are very welcome! i enjoyed writing it. [grin] i didn't notice the PS version limitation. oops!
    – Lee_Dailey
    Nov 19 at 15:58
















thanks for the time , the above script is working fine with Write-Information, also this requires Windows PowerShell 5.0,
– karhtik
Nov 19 at 9:42






thanks for the time , the above script is working fine with Write-Information, also this requires Windows PowerShell 5.0,
– karhtik
Nov 19 at 9:42














@karhtik - you are very welcome! i enjoyed writing it. [grin] i didn't notice the PS version limitation. oops!
– Lee_Dailey
Nov 19 at 15:58




@karhtik - you are very welcome! i enjoyed writing it. [grin] i didn't notice the PS version limitation. oops!
– Lee_Dailey
Nov 19 at 15:58










up vote
1
down vote













I am posting the full script which is working good with write-progress



Set-ExecutionPolicy Unrestricted -force
# Getting Filehash
Write-Host " "
Write-Host "----------------------------------------------------------------------"
Write-Host "Before Proceed, Copy the full Directory path or file path " -ForegroundColor White -BackgroundColor DarkMagenta
Write-Host "----------------------------------------------------------------------"
Write-Host " "
cd
cd .script
$a=hostname
$output=$a+'hash.txt'
$TargetDir = Read-Host 'Please enter the full path to the target Directory '
$FileList = Get-ChildItem -LiteralPath $TargetDir -Recurse -File
$filecount= $FileList.count
$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Progress -Activity "MD5 Check Processing :- $FL_Item " -Status "Processed $Counter of $filecount" -PercentComplete (($Counter / $FileList.Count) * 100)
# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)
# send to text file
$Results |
Format-Table -HideTableHeaders -AutoSize | Out-File -FilePath $output -Width 200





share|improve this answer





















  • @Lee_Dailey thanks for the tips and script i used your idea to make this answer , T.Anand thanks for the time, the answer is combination of the both the script you guys provided
    – karhtik
    Nov 19 at 9:57










  • you are most welcome! glad to have helped a little ... [grin]
    – Lee_Dailey
    Nov 19 at 15:56















up vote
1
down vote













I am posting the full script which is working good with write-progress



Set-ExecutionPolicy Unrestricted -force
# Getting Filehash
Write-Host " "
Write-Host "----------------------------------------------------------------------"
Write-Host "Before Proceed, Copy the full Directory path or file path " -ForegroundColor White -BackgroundColor DarkMagenta
Write-Host "----------------------------------------------------------------------"
Write-Host " "
cd
cd .script
$a=hostname
$output=$a+'hash.txt'
$TargetDir = Read-Host 'Please enter the full path to the target Directory '
$FileList = Get-ChildItem -LiteralPath $TargetDir -Recurse -File
$filecount= $FileList.count
$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Progress -Activity "MD5 Check Processing :- $FL_Item " -Status "Processed $Counter of $filecount" -PercentComplete (($Counter / $FileList.Count) * 100)
# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)
# send to text file
$Results |
Format-Table -HideTableHeaders -AutoSize | Out-File -FilePath $output -Width 200





share|improve this answer





















  • @Lee_Dailey thanks for the tips and script i used your idea to make this answer , T.Anand thanks for the time, the answer is combination of the both the script you guys provided
    – karhtik
    Nov 19 at 9:57










  • you are most welcome! glad to have helped a little ... [grin]
    – Lee_Dailey
    Nov 19 at 15:56













up vote
1
down vote










up vote
1
down vote









I am posting the full script which is working good with write-progress



Set-ExecutionPolicy Unrestricted -force
# Getting Filehash
Write-Host " "
Write-Host "----------------------------------------------------------------------"
Write-Host "Before Proceed, Copy the full Directory path or file path " -ForegroundColor White -BackgroundColor DarkMagenta
Write-Host "----------------------------------------------------------------------"
Write-Host " "
cd
cd .script
$a=hostname
$output=$a+'hash.txt'
$TargetDir = Read-Host 'Please enter the full path to the target Directory '
$FileList = Get-ChildItem -LiteralPath $TargetDir -Recurse -File
$filecount= $FileList.count
$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Progress -Activity "MD5 Check Processing :- $FL_Item " -Status "Processed $Counter of $filecount" -PercentComplete (($Counter / $FileList.Count) * 100)
# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)
# send to text file
$Results |
Format-Table -HideTableHeaders -AutoSize | Out-File -FilePath $output -Width 200





share|improve this answer












I am posting the full script which is working good with write-progress



Set-ExecutionPolicy Unrestricted -force
# Getting Filehash
Write-Host " "
Write-Host "----------------------------------------------------------------------"
Write-Host "Before Proceed, Copy the full Directory path or file path " -ForegroundColor White -BackgroundColor DarkMagenta
Write-Host "----------------------------------------------------------------------"
Write-Host " "
cd
cd .script
$a=hostname
$output=$a+'hash.txt'
$TargetDir = Read-Host 'Please enter the full path to the target Directory '
$FileList = Get-ChildItem -LiteralPath $TargetDir -Recurse -File
$filecount= $FileList.count
$Counter = 0
$Results = foreach ($FL_Item in $FileList)
{
$Counter ++
Write-Progress -Activity "MD5 Check Processing :- $FL_Item " -Status "Processed $Counter of $filecount" -PercentComplete (($Counter / $FileList.Count) * 100)
# this will _silently_ skip files that are locked for whatever reason
$FileHash = Get-FileHash -LiteralPath $FL_Item.FullName -Algorithm MD5 -ErrorAction SilentlyContinue

# if this is empty, then the "else" block will show "__Error__" in the Hash column
if ($FileHash)
{
[PSCustomObject]@{
Hash = $FileHash.Hash
Path = $FileHash.Path
}
}
else
{
[PSCustomObject]@{
Hash = '__Error__'
Path = $FL_Item.FullName
}
} # end >> if ($FileHash)
} # end >> foreach ($FL_Item in $FileList)
# send to text file
$Results |
Format-Table -HideTableHeaders -AutoSize | Out-File -FilePath $output -Width 200






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 9:54









karhtik

11210




11210












  • @Lee_Dailey thanks for the tips and script i used your idea to make this answer , T.Anand thanks for the time, the answer is combination of the both the script you guys provided
    – karhtik
    Nov 19 at 9:57










  • you are most welcome! glad to have helped a little ... [grin]
    – Lee_Dailey
    Nov 19 at 15:56


















  • @Lee_Dailey thanks for the tips and script i used your idea to make this answer , T.Anand thanks for the time, the answer is combination of the both the script you guys provided
    – karhtik
    Nov 19 at 9:57










  • you are most welcome! glad to have helped a little ... [grin]
    – Lee_Dailey
    Nov 19 at 15:56
















@Lee_Dailey thanks for the tips and script i used your idea to make this answer , T.Anand thanks for the time, the answer is combination of the both the script you guys provided
– karhtik
Nov 19 at 9:57




@Lee_Dailey thanks for the tips and script i used your idea to make this answer , T.Anand thanks for the time, the answer is combination of the both the script you guys provided
– karhtik
Nov 19 at 9:57












you are most welcome! glad to have helped a little ... [grin]
– Lee_Dailey
Nov 19 at 15:56




you are most welcome! glad to have helped a little ... [grin]
– Lee_Dailey
Nov 19 at 15:56


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53367889%2fhow-to-use-write-progress-in-get-filehash%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno