Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Thursday, October 1, 2020

Powershell: calculate file hash - MD5, SHA256, SHA1


 > Get-FileHash <file-name>

By default, it outputs the SHA256 of the file.


To get the file's MD5:

> Get-FileHash <file-name> -a md5


To get the file's SHA1:

> Get-FileHash <file-name> -a sha1


Wednesday, January 29, 2020

Powershell Script: Write to a file


1. Append a string to the end of a file

Add-Content -Path .\theFile -Value "the string to be appended"


2. Append file_a to the end of file_b

Get-Content -Path .\file_a | Add-Content -Path .\file_b


3. Create a new file with a sting as the content

"the string to be put into the file" | Out-File -FilePath .\theFile


Tuesday, January 28, 2020

Powershell Script: Read input with default value


$defaultVal = 'No'

$inputVal = Read-Host -Prompt "Input something? [$defaultVal]"

if ($inputVal -eq '')
{
  $inputVal = $defaultVal
}


 
Get This <