Skip to content

Instantly share code, notes, and snippets.

View FriedrichWeinmann's full-sized avatar

Friedrich Weinmann FriedrichWeinmann

View GitHub Profile
@FriedrichWeinmann
FriedrichWeinmann / Register-ShellExtension.ps1
Last active June 14, 2020 09:20
Register explorer shell extensions
function Register-ShellExtension {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$Name,
[Parameter(Mandatory = $true)]
[string]
$Text,
@FriedrichWeinmann
FriedrichWeinmann / DisableScreensaver.ps1
Created December 17, 2019 09:19
Makes PowerShell claim to be an active video player & backup software - no screensaver, no standby
$source = @'
using System;
using System.Runtime.InteropServices;
namespace Shell
{
public static class Host
{
public static void DisableScreensaver()
{
NativeMethods.SetThreadExecutionState(ExecutionState.DisplayRequired);
@FriedrichWeinmann
FriedrichWeinmann / rollingdice.ps1
Created October 2, 2019 19:06
The one command a P&P RPG player needs from PowerShell
$ExecutionContext.InvokeCommand.CommandNotFoundAction = {
param (
[string]
$CommandName,
[System.Management.Automation.CommandLookupEventArgs]
$Lookup
)
if ($CommandName -match '^(\d+)[WD](\d+)$')
@FriedrichWeinmann
FriedrichWeinmann / Out-Default.ps1
Last active June 11, 2019 04:30
Adds caching to Out-Default
function Out-Default
{
<#
.SYNOPSIS
A wrapper for Out-Default, adding automatic caching to all output sent to screen.
.DESCRIPTION
A wrapper for Out-Default, adding automatic caching to all output sent to screen.
Maximum capacity can be configured by setting $global:OutputCacheSize
@FriedrichWeinmann
FriedrichWeinmann / poc-moduleScopeHierarchy.ps1
Last active May 30, 2019 20:31
Demonstrates the scope pyramid for functions in Modules
New-Module -Name Test -ScriptBlock {
function Get-Test1
{
[CmdletBinding()]
param ()
$var = 24
$depth = 0
try
{
function Get-ShellBuffer
{
[CmdletBinding()]
param ()
try
{
# Define limits
$rec = New-Object System.Management.Automation.Host.Rectangle
$rec.Left = 0
$scriptBlock = {
Connect-Lab
$id = "<id>"
$labname = "wsFund$($id)"
$domainName = "lab$($id).contoso.com"
$labSources = 'C:\LabSources'
$image = 'Windows Server 2016 Datacenter Evaluation (Desktop Experience)'
New-LabDefinition -Name $labname -DefaultVirtualizationEngine HyperV
@FriedrichWeinmann
FriedrichWeinmann / badFunction.ps1
Created November 26, 2018 07:46
As bad as it gets
#----------------------------------------------------------------------------#
# Parameters #
#----------------------------------------------------------------------------#
# Path to a file with server names
$servers = 'DC', 'AdminHost'
# Whether errors should be ignored
$ignoreErrors = $true
Write-Host "Didn't really expect me to do a thing, did you?"
# Dummy script file for a tutorial
@FriedrichWeinmann
FriedrichWeinmann / FredsIronScripter2018.types.ps1xml
Created January 28, 2018 12:25
Type extension for serialization
<?xml version="1.0" encoding="utf-8"?>
<Types>
<!-- Fred.IronScripter2018.DiskInfo -->
<Type>
<Name>Deserialized.Fred.IronScripter2018.DiskInfo</Name>
<Members>
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
<NoteProperty>