Hi all,
So I am very new to powershell and have been asked to work on a little project here at work. We have a current script that takes your input <File location, file where to save, and saved file name> and takes the file location and hashes the files to sha56 and saves the file to a txt file. Below is the code. What I am looking to have happen is once the file is saved, I would like for a prompt to maybe ask “Do you want to compare this to another file?” and if you say yes, you input the location and name of the file and then compares the hash of that file to the one that was just created. Any ideas?
param([string]$titlehashlocation=“”,[string]$title2hashstorage=“”, [string]$sha256=“” )
Function hash{
if([string]::IsNullOrWhiteSpace($titlehashlocation))
{
write-host null or whitespace
exit
if(Test-Path -Path $titlehashlocation)
{
write-host “filepath is confirmed starting hashing of the files”
}
else
{
write-host “fliepath does not exist”
exit
}
}
else
{
if(Test-Path -Path $titlehashlocation)
{
write-host “filepath is confirmed starting hashing of the files”
}
else
{
write-host “fliepath does not exist”
exit
}
}
if([string]::IsNullOrWhiteSpace($title2hashstorage))
{
write-host storage value is null
exit
}
else
{
if([string]::IsNullOrWhiteSpace($sha256))
{
write-host ull value detected
}
else
{
$date = Get-Date
$dirend = “C:\pscript”
cd $titlehashlocation
gci $titlehashlocation.Split(‘.’) -Recurse | % {Get-FileHash $.Fullname } |Format-List > $title2hashstorage/$sha256
gci $titlehashlocation.Split(‘.’) -Recurse | % {Get-FileHash $.Fullname } |Out-GridView
“-----------------------------------------------------------------------” >> $title2hashstorage/$sha256
“-----------------------------------------------------------------------” >> $title2hashstorage/$sha256
“-----------------------------------------------------------------------” >> $title2hashstorage/$sha256
“Hash Generated at $date” >> $title2hashstorage/$sha256
write-host “hashing is complete! :)”
cd $dirend
}
}
}
hash $titlehashlocation