Skip to content

Instantly share code, notes, and snippets.

View Graham-Beer's full-sized avatar

Graham Beer Graham-Beer

View GitHub Profile
class AwsInstance {
[String] $TagName
[String] $InstanceId
[String] $Status
Hidden [Object] $EC2Instance
AwsInstance([String]$name) {
if ($name -match '^i-[a-f0-9]+$') {
$this.InstanceId = $name
@Graham-Beer
Graham-Beer / Invoke-FileSystemWatcher.ps1
Created June 20, 2018 07:56
Creation of File System Watcher class and subscribed events.
enum EventName {
Created
Changed
Deleted
Renamed
}
function Invoke-FileSystemWatcher {
[CmdletBinding()]
param (
@Graham-Beer
Graham-Beer / Find-PipelineParameters.ps1
Created July 12, 2018 18:32
Discover pipeline parameters on cmdlets
filter Find-PipelineParameters {
param (
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)]
[System.Management.Automation.CommandInfo] $CommandInfo
)
$commandInfo.Parameters.Values | Where-Object {
$parameterAttribute = $_.Attributes |
Where-Object { $_ -is [Parameter] }
$parameterAttribute.ValueFromPipeline -or $parameterAttribute.ValueFromPipelineByPropertyName
}
@Graham-Beer
Graham-Beer / Format-Member.ps1
Last active September 4, 2018 13:10
Alternative to Get-Member with a cleaner output to host
function Format-Member {
[CmdletBinding()]
[alias("fm")]
param (
[parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)]
[System.Management.Automation.PSObject]
$InputObject
)
@Graham-Beer
Graham-Beer / aes-encryption.ps1
Created September 5, 2018 16:02
Encrypter / Decrypter
## A PowerShell conversion of the C# code in the article, https://www.c-sharpcorner.com/article/aes-encryption-in-c-sharp/ ##
using namespace System.IO
using namespace System.Security.Cryptography
class ManageAes {
static [void] Main() {
[string] $data = Read-Host -Prompt "Enter text that needs to be encrypted"
[ManageAes]::EncryptAesManaged($data)
}
@Graham-Beer
Graham-Beer / Get-BinaryToText.ps1
Created December 10, 2018 09:07
Convert binary to text
function Get-BinaryToText {
param (
[Parameter(ValueFromPipeline)]
[String] $string
)
process {
($string -split ' ' |
ForEach-Object {
[char](
[convert]::ToInt32($_, 2)
function Get-BitLockerStatus {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline)]
[Microsoft.ActiveDirectory.Management.ADComputer] $Computers,
[parameter(Mandatory)]
[pscredential] $Credential
)
process {
function Invoke-BalloonMessage {
Param (
[Parameter(Mandatory)]
[string] $Message,
[Parameter()]
[string] $Title = "Attention $env:username",
[Parameter()]
[ValidateSet('none', 'Info', 'Warning', 'Error')]
function Invoke-FileArchive {
param (
[Parameter(
Mandatory,
Position = 0,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[Alias('FullName')]
[System.IO.FileSystemInfo[]] $Path,
# PowerShell script file to be executed as an AWS Lambda function.
#
# When executing in Lambda the following variables will be predefined.
# $LambdaInput - A PSObject that contains the Lambda function input data.
# $LambdaContext - An Amazon.Lambda.Core.ILambdaContext object that contains information about the currently running Lambda environment.
#
# The last item in the PowerShell pipeline will be returned as the result of the Lambda function.
#
# To include PowerShell modules with your Lambda function, like the AWSPowerShell.NetCore module, add a "#Requires" statement
# indicating the module and version.