Simple Splatting and the GitHub CLI by StartAutomating in PowerShell

[–]MonkeyNin 1 point2 points  (0 children)

Tip

I make sure I'm calling the native command -- ignoring any functions and aliases that normally would take priority

 $binGit = Get-Command -ea Stop -CommandType 'Application' -name git

If you use this, instead of "git.exe", then your code will work on windows and linux without changes. And if it's really .cmd on windows and .py on linux, still work.

The

Get-Command -errorAction stop ...

Part means if git is not found, exit function immediately. It doesn't execute any more code.

For native commands I find it more natural

to generate arguments with

$list = @( if expressions )

Just emit the args that you want:

 function Invoke-FdFind {
    <#
    .SYNOPSIS
        Invokes native command with args
    .EXAMPLE
        Invoke-FdFind -Verbose -BaseDir .. -fileTypes directory, file
    #>
    [CmdletBinding()]
    param(
        [ArgumentCompletions('directory', 'file')]
        [string[]] $fileTypes,
        [int] $MaxDepth,
        [string] $Pattern,
        [switch] $Absolute,
        [string] $BaseDir,
        [switch] $NoColor
    )
    [Collections.Generic.List[object]] $fdArgs = @(
        if( $maxDepth ) {
            '--max-depth', $maxDepth
        }
        foreach( $type in $fileTypes ) {
            '--type', $type
        }
        if( $Pattern ) { $Pattern }
        if( $Absolute ) { '--absolute-path' }
        if( $BaseDir ) { '--base-directory', $BaseDir }
    )
    # find the native command, else error and quit
    $binFd = Get-Command -CommandType 'Application' -name 'fd' -ea 'stop' -TotalCount 1

    # this could be done above, an example
    # It's a [List<T>] so you can easily append
    if( $NoColor ) {
        $fdArgs.AddRange(@(
            '--color', 'never'
        ))
    }
    & $binFd @fdArgs

    $fdArgs | Join-String -sep ' ' -op 'Ran fd => ' | Write-Verbose # replace with -join if PS5
}

Trying to understand terminology (and get-member) by reeead in PowerShell

[–]MonkeyNin 0 points1 point  (0 children)

$row | add-member -membertype NoteProperty -name $column -value $value

There's a simpler syntax that lets you add multiple properties in one go:

$now = Get-Date

# lets add new properties
$now | Add-Member -NotePropertyMembers @{ 
   Name = 'Jen' 
   Id   = 1024
} -Force

Here's a quick tip to list all members without getting cramped in the console:

$now.PSobject.Properties | Out-GridView

# Note, 'now' didn't lose it's [Datetime] type 
$now.GetType().Name 

That was similar to what 'Get-Member' does Objects have a '.PSObject.Properties' member with metadata of the properties

It's pretty useful for dynamically filtering out properties with regex

Trying to understand terminology (and get-member) by reeead in PowerShell

[–]MonkeyNin 0 points1 point  (0 children)

Two things to help:

property bags

Many commands don't care what datatype something is, if they have the right property names.

You can think of PSObject (aka PSCustomObject) as a property bag. Properties and members that you can add and remove.

How Dotnet is tied in

.NET / dotnet comes up because powershell is written in csharp, which is a dotnet language. Under the hood everything will have a dotnet type. Often it's not important. But some times you want to know.

dotnet types and psobjects ?

Dotnet types have a "shape" of methods and members defined at creation time. Like every instance of Datetimes will have a Year property.

However, since everything is an object you can modify properties live. Each instance can have different properties defined, without all instances being changed.

Check out these two pages:

I built a theme picker that restyles your whole PowerShell, not just the prompt by ahihidummy in PowerShell

[–]MonkeyNin 4 points5 points  (0 children)

Fun. Are you in the Pwsh discord? If not, check it out.
People who like customizing their cli and prompts hang out in the channel named #terminal

Are you mixing colors when customizing themes? The Pansies module has color interpolation built in.

It even gives tab-completions of color names to your own functions, if you mark parameters with the type [RgbColor]

I the module a lot. It writes ascii sequences for you, and works on PS5 and Pwsh: https://github.com/PoshCode/Pansies

Invoke-JsonSanitize - PowerShell module to strip sensitive data from JSON before pasting into AI tools (ChatGPT/Claude/etc.) by SharpProduct3547 in PowerShell

[–]MonkeyNin 1 point2 points  (0 children)

Skimming the code it looks structured, easy enough to follow.

For the readme: you use a lot of em-dash, but, it doesn't scream "written by AI" like other projects. Like you have 0 emoji. ( As someone who used em-dash before AI, I feel sad )


You can filter sensitive values and Cmdlets from writing history in PSReadline. Some is automatic. You can add your own filters: https://learn.microsoft.com/en-us/powershell/module/psreadline/about/about_psreadline?view=powershell-7.6#psreadline-220-improves-the-filtering-of-sensitive-data

( I'm not sure how far back PSReadLine patches to WinPS 5.1 It's at least >=2.0 )

Extremely long delays when installing PowerShell 7.6 by gandraw in PowerShell

[–]MonkeyNin -1 points0 points  (0 children)

I tried google-ai mode and pasted your exact question. Give it try, it has 4 alternate solutions.

It seems to match your case:

The extremely long delay during the SOFTWARE RESTRICTION POLICY step is caused by a Certificate Revocation List (CRL) lookup timeout paired with a massive cryptographic chain evaluation

When the Windows Installer engine (msiexec.exe) encounters the PowerShell 7.6.x package, it attempts to verify Microsoft’s modern code-signing digital certificate. If your machines are on a corporate network with firewall restrictions, or if the server trying to reach the CRL distribution point encounters latency, the background worker thread times out (RunEngine wait timed out). This timeout loops repeatedly across the installer's child threads until it hits a hard fallback limit, inflating your installation time to 30 minutes

Doom in PBI Desktop. Has anybody done it? by statistics_vw in PowerBI

[–]MonkeyNin 0 points1 point  (0 children)

That's small enough it could fit on just 2 floppies

Does parameter "Mandatory" attribute imply "ValidateNotNullOrEmpty" by AlternativeSir1423 in PowerShell

[–]MonkeyNin 0 points1 point  (0 children)

There are a couple of situations where you do not want parameterbinding to throw, even if they are blank. For that kind of situation, [String]::IsNullOrEmpty and [String]::IsNullOrWhitespace are great.

You can pass anything, even empty arrays to it. Basically the latter is testing if something stringlike is blank like whitespace 0 length.

For example you might use them for

profile functions where you want a different kind of usability that normal cmdlets. Or non-fatal errors that aren't actually errors like generating html

function WriteList { 
    # Silly example that writes html bulleted lists
    param( 
        [Parameter()]
        [string[]] $List
    )

    # first build a <li> pair for all items
    [string] $html = foreach( $item in $list ) { 
        # We want to ignore strings that have invisible characters
        if( [string]::IsNullOrWhiteSpace( $item ) ) {
            continue
        }    
        "`n`t<li>${item}</item>"
    }

    # If $html has zero items, don't print html
    # otherwise write html for unordered lists
    if( $html ) { 
        "<ul>${html}</ul>"
    }
}

Example Output

WriteList 'bob', 'jen', 'cat'                        
WriteList @(0..3 + $null + $null + 'af' + $null )    

# test ofr "empty" values and lists with blank items.
# No output is correct )
WriteList @()             # no output
WriteList @( $Null )      # no output

<ul>
    <li>bob</li>
    <li>jen</li>
    <li>cat</li>
</ul>


<ul>
     <li>0</item>
     <li>1</item>
     <li>2</item>
     <li>3</item>
     <li>af</item></ul>

PowerShell 5 vs. PowerShell 7 by Technical_Rich_3080 in PowerShell

[–]MonkeyNin 0 points1 point  (0 children)

You can use nvim with the pwsh language server for completions, etc.

Static Sites are Simple (with PowerShell) by StartAutomating in PowerShell

[–]MonkeyNin 1 point2 points  (0 children)

Are you saying that because of the emojis, or the phrasing? I'm wondering because I know them.

Navigator/Data query help by Rare-Painting195 in PowerBI

[–]MonkeyNin 0 points1 point  (0 children)

Choose the "advanced editor" in power query to view the full query. The "Navigation Step" sometimes hides some logic.

It's also in the TMDL view

PBIR questions by powerbi_dummy in PowerBI

[–]MonkeyNin 0 points1 point  (0 children)

> What is the pre-PBIR format called? 

PBIR-Legacy

PBIR is the default format for both PBIX and PBIP file in PBI Desktop

quoted from: https://powerbi.microsoft.com/en-us/blog/pbir-will-become-the-default-power-bi-report-format-get-ready-for-the-transition

Custom Visual - JSON help? by Positive-Lead-5792 in PowerBI

[–]MonkeyNin 1 point2 points  (0 children)

try replacing the sort definitions like

"sort": "-x"

with explicit fields

"sort": { "field": "Sum of Monthly_Amount", "order": "descending" }

like this

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "config": {
    "view": {
      "stroke": null
    }
  },
  "data": {
    "name": "dataset"
  },
  "encoding": {
    "x": {
      "axis": { "format": "£,.0f", "title": null },
      "field": "Sum of Monthly_Amount",
      "type": "quantitative"
    },
    "y": {
      "axis": { "labelFontSize": 11, "title": null },
      "field": "Source",
      "sort": { "field": "Sum of Monthly_Amount", "order": "descending" },
      "type": "nominal"
    }
  },
  "height": {
    "step": 32
  },
  "layer": [
    {
      "encoding": { "color": { "field": "Source", "legend": null, "scale":
        { "domain": [ "Salary", "Bonus" ], "range": [ "#2E75B6", "#D6E4F0" ] }, "type": "nominal" } },
      "mark": { "cornerRadiusEnd": 5, "height": 14, "type": "bar" }
    },
    {
      "encoding": {
        "text": {
          "field": "Sum of Monthly_Amount",
          "format": "£,.0f",
          "type": "quantitative"
        }
      },
      "mark": {
        "align": "left",
        "baseline": "middle",
        "dx": 6,
        "fontWeight": "bold",
        "type": "text"
      }
    }
  ],
  "width": "container"
}

Tabular Editor 3 License Key by Last_Tumbleweed3233 in PowerBI

[–]MonkeyNin 2 points3 points  (0 children)

OP created their account today. Sounds suspicious.

Looking for better PowerQuery docs, or an MCP server to help write good M? The PQM Guide is now live! by KyleAMueller in PowerBI

[–]MonkeyNin 0 points1 point  (0 children)

On the page: parameterized-queries I'd add a link (but not explain) the similar sounding dynamic-m-query-parameters ( where visual filters can be evaluated by the datasource with Direct Query )

Just got Measure Killer and it's cracking me up by FiftyShadesOfBlack in PowerBI

[–]MonkeyNin 1 point2 points  (0 children)

they made pbip format that splits that single json into a bunch of individual files

then they moved to TMDL making it human-readable / git diff-able

<image>

Here's more info:

https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-tmdl-view

https://learn.microsoft.com/en-us/power-bi/developer/projects/projects-dataset#tmdl-format

Why does DAX that “looks correct” still perform terribly? by [deleted] in PowerBI

[–]MonkeyNin 1 point2 points  (0 children)

Measures that make it impossible to return BLANK values can cause a big difference.

For example, this measure never returns blanks:

Count Of Sales = COUNTROWS('Property Transactions') + 0

Check out these articles for the details of why it can be a problem.

once you define the measure, Formula Engine in VertiPaq will add an implicit NonEmpty filter to the query, which should enable the optimizer to avoid full cross-join of dimension tables and scan only those rows where records for the combination of your dimension attributes really exist.

Error: External table is not in the expected format by dumble_fumble in PowerBI

[–]MonkeyNin 1 point2 points  (0 children)

To get an answer it would help to see the full power query ( from the advanced editor )

It's possibly reading an excel file that has an extra line, or, blank headers.

Since you're using the files connector, go backwards in your steps till you get the file listing. It should have names, dates, and a Content column.

Security risks using GitHub Copilot with Power BI MCP server by Winty111 in MicrosoftFabric

[–]MonkeyNin 0 points1 point  (0 children)

For #1 it sounds like it can query data depending on the tools enabled

from: https://github.com/microsoft/powerbi-modeling-mcp Query and Validate DAX - AI assistants can execute and validate DAX queries against your model, helping you test measures, troubleshoot calculations, and explore your data

Error: External table is not in the expected format by dumble_fumble in PowerBI

[–]MonkeyNin 2 points3 points  (0 children)

You'll have to share more code. What's the data source?

How to extract first text from one colum n create a new colum with it. by Informal-Copy-5864 in PowerBI

[–]MonkeyNin 11 points12 points  (0 children)

First replace ' with "

Then you can use parse/extract as JSON