-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction_CheckFolderForHash.ps1
More file actions
49 lines (46 loc) · 1.5 KB
/
Function_CheckFolderForHash.ps1
File metadata and controls
49 lines (46 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function CheckFolderForHash {
Param($ComputerFolder,
$HashList)
##Gather List of Files in folders
$File_list = New-Object System.Collections.ArrayList
$folder_list = New-Object System.Collections.ArrayList
foreach($Item in Get-ChildItem -path $ComputerFolder -force){
if($item.Mode[0] -eq "d"){
$folder_list.add($item.FullName) | Out-Null
write-host $item.fullname
}
else{
$File_list.Add($item.FullName) | Out-Null
Write-Host $item.FullName
}
}
while($folder_list){
foreach($folder in $folder_list.ToArray()){
foreach($item in Get-ChildItem -Path $folder -Force){
if($item.Mode[0] -eq "d"){
$folder_list.add($item.FullName)
}
else{
$File_list.Add($item.FullName)
}
}
$folder_list.Remove($folder)
}
}
## Compare Hash of files to Hashes given
foreach($file in $File_list){
$hash = Get-FileHash $file -ErrorAction SilentlyContinue
if($HashList -contains $hash.Hash){
Write-Host "`nHash is found!" $hash.Hash $hash.Path "`n"
if((Read-Host -Prompt 'Continue? (Y/N)') -eq 'N'){
break
}
else{
continue
}
}
else{
write-host $hash.Hash $hash.Path
}
}
}