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-PSCmdletSource { | |
[CmdletBinding()] | |
[OutputType([string])] | |
[Alias('oss')] | |
param( | |
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] | |
[ValidateNotNullOrEmpty()] | |
[Alias('Name')] | |
[string[]] | |
$CmdletName, |
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
var sessionState = InitialSessionState.CreateDefault(); | |
sessionState.ImportPSModule(new string[] { "AzureRM.Profile" }); | |
using (var psRunspace = RunspaceFactory.CreateRunspace(sessionState)) | |
{ | |
using (var ps = PowerShell.Create()) | |
{ | |
// This is not intuitive and an unnecessary annoyance | |
ps.Runspace = psRunspace; |
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 Compare-ObjectEquivalence { | |
[CmdletBinding(DefaultParameterSetName='Deserialized')] | |
param( | |
[Parameter(Position=0, Mandatory=$true)] | |
[ValidateNotNull()] | |
[System.Object] | |
$OriginalObject, | |
[Parameter(Position=1, Mandatory=$true, ParameterSetName='Deserialized')] | |
[ValidateNotNull()] |
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
#region Fix important *nix commands. | |
# PowerShell comes with some predefined aliases built-in that are designed to | |
# ease the transition from *nix to PowerShell. While this is well-intentioned, | |
# it hides the true power that is available in these *nix commands, and it | |
# makes it much more difficult to compare and contrast between native commands | |
# in PowerShell and their *nix counterparts. This block of code removes the | |
# predefined aliases that would otherwise hide these important *nix commands. | |
foreach ($nixCommand in @('cat','cp','curl','diff','echo','kill','ls','man','mount','mv','ps','pwd','rm','sleep','tee','type','wget')) { |
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
<# | |
.SYNOPSIS | |
Show all verbs in an easy-to-read grid. | |
.DESCRIPTION | |
Show all verbs in a grid, with custom sorting applied so that we can quickly scan each column and find verbs more easily. | |
This command was designed for ad-hoc use only. To get the most value out of this command, place it in your profile script. It outputs format data which is not easily used in automated commands. | |
#> | |
function verbs { | |
# Get the verbs in a sorted list |
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
New-Module -Name BetterScriptDiscovery -ScriptBlock { | |
# First, let's make sure we have a PSScriptPath environment variable that initializes | |
# the same way that the PSModulePath environment variable does | |
$currentUserScriptsPath = [System.IO.Path]::Combine([System.Environment]::GetFolderPath('MyDocuments', [System.Environment+SpecialFolderOption]::DoNotVerify), 'WindowsPowerShell', 'Scripts') | |
$allUserScriptsPath = [System.IO.Path]::Combine([System.Environment]::GetFolderPath('ProgramFiles', [System.Environment+SpecialFolderOption]::DoNotVerify), 'WindowsPowerShell', 'Scripts') | |
$userPsScriptPath = [System.Environment]::GetEnvironmentVariable('PSScriptPath', [System.EnvironmentVariableTarget]::User) | |
$processPsScriptPath = [System.Environment]::GetEnvironmentVariable('PSScriptPath') | |
if ($processPsScriptPath -eq $null) { | |
$processPsScriptPath = '' | |
} |
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
# Treat all files in this project as binary. This enables atomic | |
# checkins (no merges, these are signed files) and it preserves | |
# CRLF line endings | |
* binary |
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
# IMPORTANT NOTE: This hack has evolved, and HistoryPx is now a full PowerShell module | |
# that is hosted on GitHub and can be found here: github.com/KirkMunro/HistoryPx | |
# First set up some interesting hacks | |
New-Module -Name HistoryPx -ScriptBlock { | |
$PSModule = $ExecutionContext.SessionState.Module | |
$global:__ = $null | |
$global:MaximumDetailedHistoryCount = 50 | |
$global:PSDefaultParameterValues['Out-Default:OutVariable'] = 'global:__' | |
$commandHistory = [ordered]@{} |
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([System.Management.Automation.PSModuleInfo])] | |
param( | |
# The name of the module to install from GitHub. | |
[Parameter(Position=0, Mandatory=$true)] | |
[ValidateNotNullOrEmpty()] | |
[System.String[]] | |
$ModuleName, | |
# The scope from which the module should be discoverable. |
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
# Get all commands included in the ScsmPx module | |
Get-ScsmPxCommand | |
# Get all commands included in the SCSM native modules | |
Get-SCSMCommand |
NewerOlder