Jacob loves Rockstar
Jacob loves Rockstar

Reputation: 230

Make a PowerShell script safer in storage

I don't believe there is a 100% way to protect my PowerShell scripts, but I would like to be able to detect any changes that are made. One way I have found to do this, is to create a hash value of the script, a count of lines and the current date and time.

$Current_DateTime = get-date
$Get_Content = Get-Content C:\Doh\PoSH_Scripts\Important_Script.ps1 | measure-object
$Get_Hash = Get-FileHash -Path C:\Doh\PoSH_Scripts\Important_Script.ps1 -Algorithm SHA1
$Get_Hash1 = $Get_Hash | Format-List
$Current_DateTime, $Get_Hash1, "Count", $Get_Content.Count >> C:\Doh\PoSH_Scripts\Important_Script_hash.txt

Is there something else I can do to protect or detect my scripts?

Upvotes: 2

Views: 92

Answers (1)

Bacon Bits
Bacon Bits

Reputation: 32170

This is exactly what script signing (and code signing in general) is intended to achieve: prevent unauthorized modifications. See Get-Help about_Signing.

Upvotes: 1

Related Questions