Skip to content

Instantly share code, notes, and snippets.

View OCram85's full-sized avatar

Marco Blessing OCram85

View GitHub Profile
@OCram85
OCram85 / Get-AllADGroups.ps1
Last active January 10, 2019 13:33
Get-AllADGroups.ps1
function Get-AllADGoups {
<#
.SYNOPSIS
A brief description of the function or script.
.DESCRIPTION
Describe the function of the script using a single sentence or more.
.PARAMETER One
Description of the Parameter (what it does)
@OCram85
OCram85 / ConfirmMod.psm1
Created January 10, 2019 10:11
PowerShell Confirm Mode Test
function Invoke-MainFunc {
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[string]$message
)
Write-Verbose -Message ('Confirm is: {0}' -f $Confirm) -Verbose
Write-Verbose -Message ('Confirm is present: {0}' -f $PSBoundParameters.ContainsKey('Confirm')) -Verbose
Write-Verbose -Message ('PSBound is: {0}' -f $PSBoundParameters['Confirm']) -Verbose
Write-Verbose -Message ('Invoke.PSBound is present: {0}' -f $MyInvocation.BoundParameters.ContainsKey('Confirm')) -Verbose
Write-Verbose -Message ('Invoke.PSBound is: {0}' -f $MyInvocation.BoundParameters['Confirm']) -Verbose
@OCram85
OCram85 / Get-MyAwesomeCustomType.ps1
Created April 20, 2018 06:48
PowerShell Advanced Function: Parameter binding by TypeName
function Get-MyAwesomeCustomType {
[CmdletBinding()]
[OutputType('ModuleName.Context.Identifier')]
param()
$returnObj = [PSCustomObject]@{
somePropertyKey = 'awesome value'
foo = 'bar'
}
$returnObj.PsObject.TypeNames.Insert(0, 'ModuleName.Context.Identifier')
Write-Output $returnObj
@OCram85
OCram85 / tag-link-snippet.md
Created January 16, 2018 08:12
Simple Jekyll Tag Linking w/o plugins (beautiful-jekyll jekyll theme)
@OCram85
OCram85 / about.html
Last active October 25, 2017 15:49
PageSummary
<div class="about-container" >
<div class="about-container-header" data-toggle="tooltip" data-toggle="collapse" data-target="#aboutcontent" title="Display a summary about this page.">
<p class = "about-container-heading about-font-default">
<i class="fa fa-paperclip about-font-out" aria-hidden="true"></i>
<span class="about-prompt">
~>
</span>
<span class="about-font-cmd">
Get-Help
</span>
@OCram85
OCram85 / 01_<FunctionName>.Tests.ps1
Last active July 28, 2017 08:56
Pester Test Header
#region HEADER
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$RepoRoot = (Get-GitDirectory).replace('\.git', '')
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
$sut = $sut -replace "\d{2}`_", ''
$suthome = (Get-ChildItem -Path $RepoRoot -Exclude ".\tests\" -Filter $sut -Recurse).FullName
# Skip try loading the source file if it doesn't exists.
If ($suthome.Length -gt 0) {
. $suthome
}
@OCram85
OCram85 / AddPublicMember.ps1
Created July 14, 2017 11:08
Powershell Classes - ReadOnly Properties
hidden AddPublicMember() {
$Members = $this | Get-Member -Force -MemberType Property -Name '_*'
ForEach ($Member in $Members) {
$PublicPropertyName = $Member.Name -replace '_', ''
# Define getter part
$Getter = "return `$this.{0}" -f $Member.Name
$Getter = [ScriptBlock]::Create($Getter)
# Define setter part
$Setter = "Write-Warning 'This is a readonly property.'"
$Setter = [ScriptBlock]::Create($Setter)
@OCram85
OCram85 / ObjectCreation.ps1
Created March 27, 2017 08:29
ETS Question Details
$Res.PSObject.TypeNames.Insert(0,'Sparc.whoami')
Write-Output $Res
@OCram85
OCram85 / Test.ps1
Last active December 12, 2016 07:32
Posh5 class test with external class definition
Import-Module ClassTest -Verbose -Force
using module ClassTest
$test = [ClassTest]::new()
@OCram85
OCram85 / classtest.ps1
Created December 6, 2016 07:55
Creating Getter/Setter method within powershell class
Class FooBar {
[string]$Prop1
Foobar() {
$this | Add-Member -Name Prop1 -MemberType ScriptProperty -Value {
# This is the getter
return $this.Prop1
} -SecondValue {
param($value)
# This is the setter