I just learned about Powershell, I've been searching for more than 24 hours and reading a lot of articles, but I still haven't found a way to solve the following problems (because I'm not smart), hope someone can help.
1. How to remove blank line in output of format-list?
I wrote the following code to check the hash of a file:
powershell -noexit Write-Host '%1';get-filehash -literalpath '%1' -algorithm MD5 | format-list -property algorithm, hash; get-filehash -literalpath '%1' -algorithm SHA1 | format-list -property algorithm, hash
The following results
D:\Downloads\new 1.txt
Algorithm : MD5
Hash : B1D91A5CB33FDCD3CF24964769E23BDA
Algorithm : SHA1
Hash : 748B44A79C7FA38898C0248DE6D1B102A71B36D3
There are 5 blank lines in between the two results, how can I shorten it to just 1 line?
I also tried using select-object like this, the result was nice, but for hash functions like SHA512, it didn't show the full range but instead had "..." marks at the end.
powershell -noexit Write-Host '%1';get-filehash -literalpath '%1' -algorithm MD5 | select-object -property algorithm, hash;get-filehash -literalpath '%1' -algorithm SHA1 | select-object -property algorithm, hash;get-filehash -literalpath '%1' -algorithm SHA256| select-object -property algorithm, hash
Please note:
- I need the code on one line to add to the registry.
- I saw an answer here, but it was too complicated for me. I don't know what to do to incorporate it into my code: Remove empty lines after simple Format-list command
2. How to concurrently: display results in Powershell, copy to clipboard and output txt file?
If I use "| clip" after format-list, it doesn't work.
powershell -noexit Write-Host '%1';get-filehash -literalpath '%1' -algorithm MD5 | format-list -property algorithm, hash;get-filehash -literalpath '%1' -algorithm SHA1 | format-list -property algorithm, hash | clip
3. Output file
I can't output file to C drive (or does anyone know any other way?), so how can Powershell output file to another available drive? For example, your D drive is locked, Powershell will recognize that and output file to drive E.
Or is there a way to open notepad and automatically paste the results there, then you can choose to save the file or not?
Thank you very much for all the help.