Skip to content

Instantly share code, notes, and snippets.

@ninmonkey
ninmonkey / Powershell Performance testing -- adding to arrays is slow.md
Last active July 29, 2022 01:44
Powershell Performance -- Adding elements to arrays is **very** slow

Powershell Performance: Adding to arrays is slow

powershell array performance results

A common pattern in many languages adds an element to an array or list

elements = []
for x in range(10000):
 elements.append(x)
@ninmonkey
ninmonkey / Get-ADUser verses Get-AzureADUser query filters.md
Last active June 24, 2021 14:24
Get-ADUser verses Get-AzureADUser filtering syntax

Get-ADUser verses Get-AzureADUser filtering syntax

Get-ADUser -Filter

Filters using Powershell scriptblocks

Ex:

Get-ADUser -Filter "Name -eq 'Fred Johnson'"
function h1 {
param([string]$Label)
"`n#### $label ####`n"
}
$regex = '^(.+?)([^\.]*)$'
$regex_named = '^(?<name>.+?)(?<ext>[^\.]*)$'
h1 "inputs:"
Get-ChildItem c: -File
@ninmonkey
ninmonkey / .gitignore cheatsheet on glob syntax.md
Last active June 24, 2021 14:23
.gitignore glob pattern matching example

example patterns for .gitignore files

These examples assume you created a new repository at c:\projects\cat_translator

Special Characters

character description
lines starting with '#' this is a comment, git ignores these lines
* matches everything except /
@ninmonkey
ninmonkey / .gitignore
Last active December 30, 2021 06:24
Merging multiple Web API requests as a single table in Power BI using Power Query
*.pbix
{
// example: <https://cdn.discordapp.com/attachments/447476117629304853/797526322200576030/Expand_Aliases_and_Splatting.mp4>
"powershell.codeFormatting.autoCorrectAliases": true,
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.useConstantStrings": true,
"files.defaultLanguage": "${activeEditorLanguage}",
"files.trimTrailingWhitespace": true,
"terminal.integrated.shell.windows": "C:/Program Files/PowerShell/7/pwsh.exe",
"terminal.integrated.shellArgs.windows": [
"-NoLogo"
@ninmonkey
ninmonkey / Replace one value in a table.pq
Created July 9, 2020 00:52
replacing one column in one record of a table
// replace bad name
let
/* ignore this chunk */
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSspPUtJRMgRiI0NjQxMTpVidaKW0otQUkAgQGxsZm5iZGUPEczOLizPz0kHCQGxibGRqZgSVgphjAtJlbGKqFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [name = _t, customer = _t, UID = _t]),
#"Changed Type" = Table.TransformColumnTypes(
Source,{
{"name", type text}, {"customer", Int64.Type}, {"UID", Int64.Type}
}),
/* select record, modify it, then call Replace
@ninmonkey
ninmonkey / RandomSales.pq
Last active July 13, 2020 01:20
Generating tables PowerQuery
let
Source = #"gen DateTimes",
TableDates = Table.FromList(
Source,
Splitter.SplitByNothing(),
{"SaleDate"},
null,
ExtraValues.Error
),
@ninmonkey
ninmonkey / Test VsCode breakpoints.ps1
Created July 13, 2020 18:12
Test VsCode breakpoints in powershell
# [test]: only breakpoint in a pipe, not on first statement
Get-PSReadLineKeyHandler -bound -unbound # yes
| ? Group -eq Basic # no
| Join-String -seperator ', ' -property Key # no
| Out-Null
# [test] escaped-newline, on the first expression in a pipe # no
# <<next>> line is # yes
Get-PSReadLineKeyHandler -bound -unbound `
@ninmonkey
ninmonkey / Readme.Utf8 in Python.md
Last active June 24, 2021 14:22
Piping Unicode to Python From Powershell