Questions tagged [powershell-7.0]

Use this tag for version specific questions about Windows PowerShell version 7.0. When using this tag also include the more generic [powershell] tag where possible. For general PowerShell topics, use the [powershell] tag.

216 questions
2
votes
1 answer

Strange "A positional parameter cannot be found" with Rename-Item

Using Powershell 7, this works perfectly: dir foo* | Rename-Item -Path {$_.Name} -NewName{$_.Name -replace 'bar-(.*)', 'bar-$1'} This fails: dir foo* | Rename-Item {$_.Name} {$_.Name -replace 'bar-(.*)', 'bar-$1'} With the following…
2
votes
0 answers

PowerShell: How to reliably send emails

According to the cmdlet help file, Send-MailMessage is no longer recommended for sending email, especially to SMTP servers. The .NET Platform Compatibility Note, which the documentation leads to, says to use the MailKit .NET library. Upon examining…
BroVic
  • 979
  • 9
  • 26
2
votes
3 answers

How do I make use of New-ScriptFileInfo PrivateData?

I've been using a PSD1 file, named the same as the script file (e.g. Foo.ps1 --> Foo.psd1) to store settings for my script. I was thinking that I might able to make use of the script's PrivateData section to store this information, which would be…
craig
  • 25,664
  • 27
  • 119
  • 205
2
votes
0 answers

Up-arrow history matching in powershell 7

I'd like to get history matching in powershell 7 like: when I type npm and up arrow key, it would show my last command started with the keyword npm (Ex: npm run build). I was able to achieve this in powershell 5 here. But this is not working in 7.…
Wajahath
  • 2,827
  • 2
  • 28
  • 37
2
votes
1 answer

Powershell loop is only running once file per filename, even if the filename exists with multiple extensions

I'll be the first to admit that PowerShell isn't my strong suit, but I've pieced together the following after an evening of digging around on the internet. The end goal is to organize a huge drive of images by the DateTaken, as well as sidecar XMP…
Michael
  • 23
  • 3
2
votes
2 answers

PowerShell: Cannot have local variables scoped inside a class method?

I expect that inside a class method, I can have "local" variable scoped inside of the method, but it is not the case. The following is the test code: class test_scope { $var = "class var" test_scope() { } [void] my_method() { $var =…
puravidaso
  • 1,013
  • 1
  • 5
  • 22
2
votes
2 answers

Memory usage powershell 7.03 Foreach-object Parallel

I am trying to do process across a reasonable data set and was trying the Foreach-Object -Parallel in powershell 7.x. Every time i ran i was finding that i was running out of memory It seems about 1 gig per 1000 objects and i have now distilled down…
Davey
  • 41
  • 3
2
votes
0 answers

PowerShell Invoke-RestMethod Pagination -FollowRelLink not working

I am trying to get data from a REST API which has pagination. I have tried to use the -FollowRelLink option which is part of Invoke-RestMethod but the is not working. The API Below returns a maximum of 175…
Ross
  • 2,463
  • 5
  • 35
  • 91
2
votes
1 answer

Function ported from Powershell 5 to Powershell 7 fails with "object reference not set to an instance of an object"

Following code works as expected in powershell 5.1: function Get-Say([String] $Message, [String] $Voice = "Microsoft Irina Desktop") { Add-Type -AssemblyName System.speech $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer …
shabunc
  • 23,119
  • 19
  • 77
  • 102
2
votes
1 answer

PS7.1 - How do you use pipeline chaining with custom functions?

According to documentation, PS 7 has introduced pipeline chaining operators such as || and &&. https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipeline_chain_operators?view=powershell-7 And you should be…
Kir
  • 2,905
  • 2
  • 27
  • 44
2
votes
1 answer

How to stop a child process with Ctrl+C without breaking the main script and stream child output to the main script in PowerShell?

I am writing a powershell script that is running on Linux. The purpose of this script is to run the MS SQL Server and show its output, but when the user presses Ctrl+C or some error happens, the script takes a copy of the data folder and then after…
1
vote
1 answer

Unable to use .Net class via the Add-Type cmdLet in PowerShell 7

I have a PowerShell script that listens for a key to be pressed before exiting. I accomplish this using a custom TypeDefinition; here's the code: param( [string]$quitKey = "F16" ) $keyLogger = @" using System; using System.IO; using…
ninbura
  • 450
  • 6
  • 14
1
vote
0 answers

PowerShell 7 Cmdlets not recognized when using AWS SSM Automation document script

Trying to figure out why 3 powershell cmdlets are not working when using AWS SM Automation inputs Script, but they do work when running them in a local script directly on my Windows instances. The cmdlets: get-ciminstance and rename-computer work in…
1
vote
1 answer

VSCode breaks my powerShell associations once a ps1 file is opened with that editor

I have a strange problem with Visual Studio code related to selecting the default Powershell version: I have installed Powershell 5.1 and 7 parallely, but when I doubleclick on a ps1-file, it should automatically run the Powershell 5 console and…
Erik
  • 2,316
  • 9
  • 36
  • 58
1
vote
2 answers

How to upgrade PowerShell version

Lately, firing up PowerShell, I noticed that there is a phrase that says: Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows So why not trying it following the actual Microsoft documentation: I run…
Francesco Mantovani
  • 10,216
  • 13
  • 73
  • 113