Skip to content

Instantly share code, notes, and snippets.

View indented-automation's full-sized avatar

Chris Dent indented-automation

View GitHub Profile
@indented-automation
indented-automation / Import-PSProvider.ps1
Last active August 13, 2021 11:05
Add a PowerShell Provider without Import-Module
using namespace System.Management.Automation
using namespace System.Management.Automation.Provider
using namespace System.Management.Automation.Runspaces
[CmdletProvider('MyProvider', [ProviderCapabilities]::None)]
class Provider : DriveCmdletProvider {
[PSDriveInfo] NewDrive( [PSDriveInfo]$drive )
{
return ([DriveCmdletProvider]$this).NewDrive($drive)
}
@indented-automation
indented-automation / Get-SqlVersionName.ps1
Last active February 8, 2017 17:00
SQL version lookup table
function Get-SqlVersionName {
param(
[Version]$Version
)
$lookup = @{
'Name' = ('Major', 'Minor', 'RTM', 'SP1', 'SP2', 'SP3', 'SP4')
'2016' = ( 13, 0, 1601, 4001 )
'2014' = ( 12, 0, 2000, 4100, 5000 )
'2012' = ( 11, 0, 2100, 3000, 5058, 6020 )
filter Write-String {
<#
.SYNOPSIS
Write a string representation of an object.
.DESCRIPTION
Write-String creates formatted string representations of an input object.
.INPUTS
System.Object
.EXAMPLE
Get-Process | Write-String
@indented-automation
indented-automation / New-Password.ps1
Last active May 7, 2024 08:57
PowerShell random password generator.
function New-Password {
<#
.SYNOPSIS
Generate a random password.
.DESCRIPTION
Generate a random password.
.NOTES
Change log:
27/11/2017 - faustonascimento - Swapped Get-Random for System.Random.
Swapped Sort-Object for Fisher-Yates shuffle.
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
using namespace System.Reflection
function Get-FunctionInfo {
<#
.SYNOPSIS
Get an instance of FunctionInfo.
.DESCRIPTION
FunctionInfo does not present a public constructor. This function calls an internal / private constructor on FunctionInfo to create a description of a function from a script block or file containing one or more functions.
Add-Type -AssemblyName PresentationFramework
[Xml]$xaml = '<?xml version="1.0" encoding="utf-8"?>
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="500" Width="500">
<DockPanel>
<Label Content="Title" DockPanel.Dock="Top" />
<Label Content="Copyright" Margin="5" DockPanel.Dock="Bottom" />
<StackPanel DockPanel.Dock="Left">
enum UserRight {
SeAssignPrimaryTokenPrivilege # Replace a process level token
SeAuditPrivilege # Generate security audits
SeBackupPrivilege # Back up files and directories
SeBatchLogonRight # Log on as a batch job
SeChangeNotifyPrivilege # Bypass traverse checking
SeCreateGlobalPrivilege # Create global objects
SeCreatePagefilePrivilege # Create a pagefile
SeCreatePermanentPrivilege # Create permanent shared objects
SeCreateSymbolicLinkPrivilege # Create symbolic links
function Remove-Service {
[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = 'ByName')]
param (
[Parameter(Mandatory = $true, Position = 1, ParameterSetName = 'ByName')]
[String]$Name,
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'FromPipeline')]
[PSTypeName('Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_Service')]
[CimInstance]$InputObject,
@indented-automation
indented-automation / New-DynamicModuleBuilder.ps1
Last active December 10, 2019 06:47
Dynamic enum creation
function New-DynamicModuleBuilder {
<#
.SYNOPSIS
Creates a new assembly and a dynamic module within the current AppDomain.
.DESCRIPTION
Prepares a System.Reflection.Emit.ModuleBuilder class to allow construction of dynamic types. The ModuleBuilder is created to allow the creation of multiple types under a single assembly.
.EXAMPLE
New-DynamicModuleBuilder
#>
function Resolve-ParameterSet {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[String]$Command,
[String[]]$ParameterName
)
try {