This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set-PSReadlineKeyHandler -Chord Spacebar -ScriptBlock { | |
param ($key, $arg) | |
$line = $null | |
$cursor = $null | |
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState( | |
[ref]$line, [ref]$cursor | |
) | |
if ($cursor -lt 3) { | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ExecutionContext.InvokeCommand.CommandNotFoundAction = { | |
param ($name, $eventArgs) | |
@( | |
"Boooo!" | |
"Don't you know anything?" | |
"RTFM!" | |
"Hahaha, n00b!" | |
"Wow! That was impressively wrong!" | |
"He said: $name :D" | |
"What are you doing??" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
[OutputType([hashtable])] | |
param ( | |
[string]$Path, | |
[string]$ClassName = '*' | |
) | |
$moduleBase = Split-Path -Path $Path -Parent | |
Write-Verbose "Module name - $fileName" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string]$Path, | |
[string]$ClassName | |
) | |
$scriptBody = @' | |
using module {0} | |
'@ -f $Path | |
$script = [scriptblock]::Create($scriptBody) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Register-ArgumentCompleter -Native -CommandName Should -ScriptBlock { | |
param ($WordToComplete, $CommandAst) | |
$options = @( | |
'Be' | |
'BeExactly' | |
'BeLike' | |
'BeGreaterThan' | |
'BeLessThan' | |
'Contain' | |
'Match' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo { | |
param ( | |
[ValidateSet( | |
'this', | |
'that' | |
)] | |
[String]$bar | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Find-ADObject { | |
<# | |
.Synopsis | |
Function to search Active Directory using specified LDAP filter. | |
.Description | |
Function uses selected LDAP filter to search Active Directory. | |
It doesn't have any external dependencies and is using ADSISearcher class. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-LoginCompletion { | |
param( | |
[string]$commandName, | |
[string]$parameterName, | |
[string]$wordToComplete, | |
[System.Management.Automation.Language.CommandAst]$commandAst, | |
[System.Collections.IDictionary]$fakeBoundParameters | |
) | |
([ADSISearcher]"(&(objectClass=user)(sAMAccountName=$wordToComplete*))").FindAll() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DopelnijVMke : System.Management.Automation.IArgumentCompleter { | |
[System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument( | |
[string]$commandName, | |
[string]$parameterName, | |
[string]$wordToComplete, | |
[System.Management.Automation.Language.CommandAst]$commandAst, | |
[System.Collections.IDictionary]$fakeBoundParameters | |
) { | |
return [System.Management.Automation.CompletionResult[]]@( | |
foreach ($vm in Get-VM -Name "$wordToComplete*") { |
NewerOlder