Use this tag for version specific questions about Windows PowerShell version 7.2. When using this tag also include the more generic [powershell] and [powershell-7.0] tags where possible. For general PowerShell topics, use the [powershell] tag.
Questions tagged [powershell-7.2]
75 questions
4
votes
1 answer
Why is the function not called by Start-ThreadJob?
I want to backup some data over my script. All data shall be zipped in a separate thread. But two things go wrong:
The function testFct is never called - indication: no "inside: ...".
The parameter ZipSource is missing - see output.
Calling the…

kirsche40
- 981
- 1
- 10
- 19
3
votes
2 answers
How can I prevent non position 0 parameters to appear in position 0 in PowerShell?
Here are my parameters of one of the nested modules in my main module:
Param(
[Parameter(Mandatory = $false, ParameterSetName = "set1", Position = 0, ValueFromPipeline = $true)][switch]$Get_BlockRules,
[Parameter(Mandatory =…

SpyNet
- 323
- 8
3
votes
4 answers
Powershell 7.2: ConvertFrom-Json - Date Handling
With Powershell 7.2 there seems to be a change in how a JSON is deserialized into an object in terms of dates -> instead of string it is now datetime. But I want to have the "old" behavior, i.e. that it is handled as string and NOT datetime.
How can…

quervernetzt
- 10,311
- 6
- 32
- 51
3
votes
1 answer
How to export variables from a PowerShell module
I've defined a variable in a psm1 file but when I try to access it in another script, after importing the module, I'm not seeing the value set in the psm1 file.
globals.psm1
$blah = "hello world"
my-script.ps1
Import-Module…

spottedmahn
- 14,823
- 13
- 108
- 178
3
votes
1 answer
Implicit conversion to bool of struct defined in C# fails in PowerShell
Why does an implicit conversion to [byte] work, but when replacing byte by bool it no longer works?
I. e. the following works...
Add-Type -TypeDefinition @'
public readonly struct MyByte
{
private readonly byte value;
public MyByte( byte b…

zett42
- 25,437
- 3
- 35
- 72
3
votes
1 answer
Accept part of the autocompletion
I have recently got myself a new Windows 11 laptop, and started exploring powershell. Never used it before on Windows, but I'm a frequest user of zsh in Mac so not completely new.
I upgraded Powershell to 7.2.1, but noticed that the auto-suggestion…

yarnabrina
- 1,561
- 1
- 10
- 30
3
votes
1 answer
PowerShell - Add-Type Issue trying to do REST call without self-signed cert issue
I'm trying to better understand Add-Type in PowerShell after running into an issue of trying to do a REST API call and avoiding a self-signed cert issue. Code is as follows.
add-type @"
using System.Net;
using…

BuddyJoe
- 69,735
- 114
- 291
- 466
2
votes
1 answer
Why do process blocks correctly return a hashtable, instead of an array of hashtables?
I am trying to sort some REST API responses and extract data from them, and found this helpful answer on how to end up with a hashtable at the end.
$res= (Invoke-RestMethod @commonParams -uri "foo" -Method GET -FollowRelLink) | ForEach-Object { $_ }…

Graham Reynolds
- 146
- 10
2
votes
2 answers
Defining parameters common to all functions within a PowerShell module
I am writing a PowerShell module, the functions inside this module have some parameters which will be re-used across all functions. Rather than copy-pasting the function definition each time I add a new function, I would like to define them at the…

David
- 21
- 2
2
votes
2 answers
How to refer to HKEY_CLASSES_ROOT in PowerShell?
New-Item -Path "HKCR:\Directory\Background\shell\customname" -Force
I've been doing the same thing for HKCU and KHLM but when I try HKCR I get errors in PowerShell. how am I supposed to do it for HKEY_CLASSES_ROOT?
I searched for a solution but…
user20225877
2
votes
1 answer
Powershell - how to read Ansi CSV file
Notepad++ says the CSV file is Ansi encoded.
The Powershell 7 Import-CSV commandlet has various -Encoding options but 'Ansi' is not one of them.
How do I get Powershell to read this CSV without mangling it?
The options for -Encoding…

codeulike
- 22,514
- 29
- 120
- 167
2
votes
0 answers
Converting extremely large JSON file to object
I have very large JSON files that I would like to explore the structure of before processing. Some of these can be in excess of 4-5 GB, but the one I've picked a smaller one just for exploration purposes. The bonus difficulty here is that the files…

HallucinationOrbit
- 21
- 1
2
votes
1 answer
PowerShell 7; String to DateTime?
This piece of code works fine in PowerShell 5.
It returns the following date/time, depending on which OS and OS language is used;
"Wed, 04 Mar 2015 07:39:54 GMT"
"woensdag 4 maart 2015 08:39:54"
However, in PowerShell 7 it no longer works and gives…

Paddy
- 123
- 7
2
votes
2 answers
Default Powershell Terminal is 7.2 but scripts run as Powershell 5.1
Notice in my VS Code, a fresh terminal, the very first line indicates it is properly defaulted to Powershell 7.2.2 - just as I believe it should.
But then in this same screenshot, the first script I run (which has a command to print out the…

bkwdesign
- 1,953
- 2
- 28
- 50
2
votes
1 answer
invoke-WebRequest and a proxy that refuses to die in Powershell 5.1
I have a Windows Server 2019 instance that used to have a proxy server configured in its proxy setting but has since been disabled from Proxy Settings -> Proxy
If I run the powershell 5.1 command:
Invoke-WebRequest https://
then i'm still…

Chris D.
- 21
- 1