Skip to content

Instantly share code, notes, and snippets.


Bartek Bielawski bielawb

View GitHub Profile
bielawb / invoke-insult.ps1
Created Nov 17, 2017
If you want your PowerShell to insult you when you run wrong command...
View invoke-insult.ps1
$ExecutionContext.InvokeCommand.CommandNotFoundAction = {
param ($name, $eventArgs)
"Don't you know anything?"
"Hahaha, n00b!"
"Wow! That was impressively wrong!"
"He said: $name :D"
"What are you doing??"
bielawb / GitAliasesHelper.ps1
Created Nov 10, 2017
Snippet that can be added to the profile to turn git aliases into PowerShell commands. Note: this solution doesn't support parameters.
View GitAliasesHelper.ps1
$gitAliases = (git config --global -l).Where{ $_ -match '^alias\.'}.ForEach{$_ -replace '^alias\.(\w+).*', '$1'}
$ExecutionContext.InvokeCommand.CommandNotFoundAction = {
param ($name, $eventArgs)
if ($name -in $gitAliases) {
$alias = $name
} elseif ($aliases = $gitAliases -match [regex]::Escape($name)) {
$alias = $aliases | Sort-Object -Property Length | Select-Object -First 1
bielawb / Get-ModuleDefinedClass.ps1
Last active Dec 30, 2016
Just an attempt to get info about classes defined by a given module.
View Get-ModuleDefinedClass.ps1
param (
[string]$ClassName = '*'
$moduleBase = Split-Path -Path $Path -Parent
Write-Verbose "Module name - $fileName"
bielawb / New-ModuleClassInstance.ps1
Created Dec 30, 2016
Work-around for the fact that `using module` is not very flexible.
View New-ModuleClassInstance.ps1
param (
$scriptBody = @'
using module {0}
'@ -f $Path
$script = [scriptblock]::Create($scriptBody)
bielawb / CompleteShould.ps1
Created Nov 29, 2016
TabExpansion for Should
View CompleteShould.ps1
Register-ArgumentCompleter -Native -CommandName Should -ScriptBlock {
param ($WordToComplete, $CommandAst)
$options = @(
bielawb / ValidateSet.Tests.ps1
Created Nov 1, 2016
Pester test for ValidateSet
View ValidateSet.Tests.ps1
function foo {
param (
bielawb / FindADObject.psm1
Created Oct 31, 2016
Module that shows how hard to read can ArgumentCompleter become when query is complex.
View FindADObject.psm1
function Find-ADObject {
Function to search Active Directory using specified LDAP filter.
Function uses selected LDAP filter to search Active Directory.
It doesn't have any external dependencies and is using ADSISearcher class.
bielawb / JIRA.psm1
Created Oct 31, 2016
Module that uses WMF5 completion for skeleton New-JiraIssue
View JIRA.psm1
function Get-LoginCompletion {
([ADSISearcher]"(&(objectClass=user)(sAMAccountName=$wordToComplete*))").FindAll() |
bielawb / ShowVM.psm1
Created Oct 31, 2016
Module that uses WMF5 completion for vmconnect wrapper.
View ShowVM.psm1
class DopelnijVMke : System.Management.Automation.IArgumentCompleter {
[System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument(
) {
return [System.Management.Automation.CompletionResult[]]@(
foreach ($vm in Get-VM -Name "$wordToComplete*") {
bielawb / ComputerName.Completer.ps1
Created Sep 28, 2016
Using TabExpansionPlusPlus to tab-complete CName -> HostName
View ComputerName.Completer.ps1
Register-ArgumentCompleter -ParameterName ComputerName -ScriptBlock {
$record = [System.Net.Dns]::Resolve($wordToComplete)
if ($record) {