Skip to content

Instantly share code, notes, and snippets.

View deangrant's full-sized avatar

Dean Grant deangrant

View GitHub Profile
@deangrant
deangrant / Create-EmailHash_ValidateScript_CustomError_Snippet
Last active October 10, 2015 11:19
Snippet for validating email address with custom error in Create-EmailHash function
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True, ValueFromPipeline=$True, HelpMessage="Enter an email address to compute hash")]
[ValidateScript({If ($_ -match "\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b") {$True}
Else {Throw "The email address $_ is not a valid email address format."}})]
[String[]]$Email
)
@deangrant
deangrant / Create-EmailHash_Compute_MD5_Snippet
Created October 10, 2015 11:36
Create-EmailHash_Compute_MD5_Snippet
Begin {} #Begin
Process
{
Write-Verbose ("The following email addresses have been specified " + ($Email -join ',') + ".")
ForEach ($String in $Email)
{
Write-Verbose ("Computing hash for the email address " + $String+ ".")
$StringBuilder = New-Object System.Text.StringBuilder
[System.Security.Cryptography.HashAlgorithm]::Create("MD5").ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String))| ForEach-Object {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True, ValueFromPipeline=$True, HelpMessage="Enter an email address to compute hash")]
[ValidateScript({If ($_ -match "\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b") {$True}
Else {Throw "The email address $_ is not a valid format."}})]
[String[]]$Email,
[ValidateSet('MD5','RIPEMD160','SHA1','SHA256','SHA384','SHA512')]
[String] $HashAlgorithm = "MD5"
)
Begin {} #Begin
Process
{
Write-Verbose ("The following email addresses have been specified " + ($Email -join ',') + ".")
ForEach ($String in $Email)
{
Write-Verbose ("Computing hash for the email address " + $String + " using the " + $HashAlgorithm + " algorithm.")
$StringBuilder = New-Object System.Text.StringBuilder
[System.Security.Cryptography.HashAlgorithm]::Create($HashAlgorithm).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String))| ForEach-Object {
@deangrant
deangrant / ConvertTo-CertificateContainer_snippet_Param
Created November 7, 2015 14:38
ConvertTo-CertificateContainer_snippet_Param
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][ValidateScript({Get-Item $_})][String[]] $Certificates,
[String] $Output = ([Environment]::GetEnvironmentVariable("UserProfile")) + "\container_file.pem"
)
Process
{
Try
{
# Retrieves and adds the content of each certificate from the specified location to a concatenated certificate container file.
ForEach ($Certificate in $Certificates)
{
Get-Content $Certificate | Add-Content $Output
}
} # Try
ConvertTo-CertificateContainer -Certificates "C:\Certificates\SSL.crt", "C:\Certificates\IntermediateCA.crt", "C:\Certificates\RootCA.crt" -Output C:\Certificates\chain.pem -Verbose
[CmdletBinding()]
Param (
[String] $Days = "1",
[Switch] $Microsoft,
[Switch] $NVD,
[String] $Keywords = "Ubuntu|Tomcat|MySQL"
)
Try
{
# Conditional logic to determine if the switch to retrieve information from the Microsoft Security Bulletin RSS feed has been specified.
If ($Microsoft)
{
# Retrieves content from the Microsoft Security Bulletin RSS feed.
[xml]$WebRequest = Invoke-WebRequest -Uri https://technet.microsoft.com/en-us/security/rss/bulletin
# Selects objects retrieved where the published date is greater or equal to the timespan speficied.
$Items = $WebRequest.rss.channel.item | Where-Object {$_.pubDate -ge "$Date"}
# Performs action on each item returned to calculate expressions for output object.
# http://powershell.org/wp/2015/12/05/december-2015-scripting-games-puzzle/
$List = @"
1 Partridge in a pear tree
2 Turtle Doves
3 French Hens
4 Calling Birds
5 Golden Rings
6 Geese a laying
7 Swans a swimming