Skip to main content

All Questions

1 vote
2 answers
238 views

Installing exe inside Windows container using PowerShell

I am facing problem with installation of .exe file inside docker container: FROM mcr.microsoft.com/dotnet/sdk:7.0 AS base SHELL ["pwsh", "-Command", "$ErrorActionPreference = '...
Julia's user avatar
  • 25
3 votes
2 answers
190 views

How to make sure a file used by a steppable pipeline is closed even in case of an exception?

This is a self-answered question. I'm going to add an answer only for PowerShell 7.3 or newer. Feel free to add answers for any previous PowerShell version. I have a custom logging function that ...
zett42's user avatar
  • 28k
4 votes
2 answers
1k views

How to get the TBS (To be signed) value of a signed file in PowerShell?

Looking for a way to get the TBS of a file that has digital signature in PowerShell 7.3+ Tried a few things like: add-type -AssemblyName system.security.cryptography.X509Certificates $cert = new-...
SpyNet's user avatar
  • 709
4 votes
3 answers
7k views

In PowerShell, how can I create a scheduled task that runs only 1 time at startup and then deletes itself?

This is what I've gathered so far. I need a scheduled task that runs only 1 time, at the next startup (whenever that is) and after it runs it should delete itself. Register-ScheduledTask -TaskName &...
SpyNet's user avatar
  • 709
1 vote
2 answers
613 views

How to set mandatory attribute of a parameter to $true conditionally in PowerShell?

The mandatory attribute accepts ScriptBlocks but as I've tested it and seen in other answers, it's always returning $true function Test-Function { param ( [Parameter (Position = 0)] ...
SpyNet's user avatar
  • 709
3 votes
0 answers
23 views

Why can't I populate strongly-typed dictionaries with ForEach-Object unless the input object is provided via pipeline (rather than parameter)? [duplicate]

Context I'm aiming to gather info about the user's Java Runtime Environment in a script for use in checking that it meets certain requirements. I start with a variable named JRE that's cast as a list ...
Magic Spearmint's user avatar
3 votes
2 answers
668 views

How to serialize/deserialize data back and forth between Windows PowerShell and PowerShell core?

I've been trying to find a solution to work with a specific cmdlet from ConfigCi built-in module that is incompatible with PowerShell core. The cmdlet is New-CIPolicyRule I want to use it in my module ...
SpyNet's user avatar
  • 709
1 vote
1 answer
716 views

PowerShell | Argument completer not working when a file with the required criteria is not in the current working directory

I've tried 2 argument completers so far for my module to only show me the files with .cer extension when I press TAB button. Here is one of them $ArgumentCompleterCertPath = { Get-ChildItem | ...
SpyNet's user avatar
  • 709
1 vote
1 answer
298 views

How to prevent PowerShell validateSet argument completer from suggesting the same values that are already selected?

I have 2 class-based argument completers/validate sets for 2 of my PowerShell module's parameters. [ValidateSet([PolicyIDz])][parameter(Mandatory = $false, ParameterSetName = "Remove Policies&...
SpyNet's user avatar
  • 709
0 votes
1 answer
860 views

How to make a PowerShell argument completer that only suggests files not already selected?

I'm not sure if it's possible to do this so going to first explain what I want to happen. my PowerShell module function has this parameter [ValidateScript({ Test-Path $_ -PathType Leaf })][...
SpyNet's user avatar
  • 709
1 vote
1 answer
229 views

Pester 5.4 generates an empty Code coverage result file

POV: I'm generating Powershell test code coverage with pester. Problem: The generated Coverage.xml file remains empty. Question What am I doing wrong? Some technicalities: Write-Verbose -Message &...
JDC's user avatar
  • 1,815