Skip to content

Instantly share code, notes, and snippets.

View iricigor's full-sized avatar
😃
🇨🇿

Igor iricigor

😃
🇨🇿
View GitHub Profile
@iricigor
iricigor / pipeline.ps1
Last active November 16, 2020 23:48
PowerShell pipeline argument binding
function fa {
[CmdletBinding()]
param (
[Parameter(Mandatory,ValueFromPipeline)]
[int]$x
)
# function 1
BEGIN {Write-Verbose "Begin a: $x"}
if ($Prefix.Length -gt 2) {
Write-Output 'Welcome'
} else {
throw '$Prefix missing'
}
Write-Output 'Groups overview'
$Groups = Get-AzADGroup -DisplayNameStartsWith $Prefix | ? DisplayName -like *Access
$Groups | Format-Table
$Groups | % {Write-Output "$($_.DisplayName) members count: $((Get-AzADGroupMember -ObjectId $_.Id).Count)"}
@iricigor
iricigor / passing-values-from-discovery.tests.ps1
Last active May 28, 2020 08:04
Passing values from Discovery to Run when generating tests
# original gist by Jakub
Describe "a" {
$Sources = @(
[PSCustomObject]@{
Advanced = @{
Enabled = $true
}
}
[PSCustomObject]@{
@iricigor
iricigor / Microsoft.PowerShell_profile.ps1
Created October 28, 2018 10:33
PowerShell profile settings
# PSReadLine tips from https://opensource.com/article/18/7/powershell-tips
Set-PSReadlineOption -EditMode Emacs
Set-PSReadlineOption -BellStyle None
# https://learn-powershell.net/2012/08/07/make-your-powershell-errors-less-harsh-by-changing-their-color/
$host.PrivateData.VerboseForegroundColor = 'DarkGreen'
# Work around an RS5/PSReadline-2.0.0+beta2 bug (Spacebar is not marked 'essential')
Set-PSReadlineKeyHandler "Shift+SpaceBar" -ScriptBlock {
@iricigor
iricigor / Continue-vs-Finally.ps1
Created October 18, 2017 19:16
Continue vs Finally in PowerShell
for ($i=-1;$i -lt 2; $i++) {
try {
"`nTry $i"
1/$i | out-null
} catch {
"Catch $i"
continue
} finally {
"Finally $i"