35 questions
1
vote
2
answers
65
views
Apply Where-Object shorthand operators to entire object
Where-Object's params providing shorthands for builtin operators, one can skip the scriptblock and write:
Get-ChildItem | Where-Object { $_.Name -match '\.(txt|md)$' }
as:
Get-ChildItem | Where-...
0
votes
0
answers
14
views
Trying to insert a variable in a New-Item to create a directory [duplicate]
I'm trying to generate a directory name with the current datetime inserted into it; then run a simple robocopy script to copy a bunch of files there.
New-Item is being uncooperative - why?
my code:
$...
-1
votes
1
answer
43
views
Trouble with Regular Expression matching in PowerShell when lines contain "$" sign
I am trying to perform search and replace using RegExs in PowerShell like the following:
Julie found "NoMoney" in "Easter Island" => Julie("Easter Island") = "...
1
vote
0
answers
23
views
PowerShell - How to make defined constants and functions accessible in ForEach-Object -Parallel
I'm working on a PowerShell script that needs to use ForEach-Object -Parallel to run several iterations of a process simultaneously. Here's my code (with names changed to protect the innocent). Right ...
1
vote
1
answer
173
views
PSCommandNotFoundSuggestion message shows without suggestions (PowerShell 7.5)
I recently upgraded to PowerShell 7.5, where PSCommandNotFoundSuggestion has become a mainstream feature.
Often, after running a successful command I see the message...
Suggestion [4,General]: The ...
2
votes
0
answers
263
views
PowerShell Constrained Language Mode doesn't work within scripts
I have an AppLocker policy that allows only scripts signed with a certificate from my company. This is the only script policy, no default created.
When I run a Windows PowerShell 5.1 or PowerShell 7 ...
0
votes
1
answer
63
views
Windows: Resolves path with .. appended to directory name
This project I'm working on has some Windows Perl code that sets a path to dirname(__FILE__) . "../../../../". This code has been working for a couple years now, but I realized that it ...
0
votes
3
answers
65
views
Weird behaviors around "." string manipulation in PowerShell
I'm using PowerShell 7.4.5.
First example: 'a.b' -split '.' does not give you a two-element array of a and b, but a four-element array of empty strings.
Another example is 'rodtipsqleastus2.database....
0
votes
2
answers
3k
views
How to get the "Windows PowerShell" version? `pwsh --version` seems to be giving the "PowerShell 7" version
In both "PowerShell 7" and "Windows PowerShell", when I do pwsh --version, I get PowerShell 7.4.5.
However, in "Windows PowerShell", when I do Set-PSReadLineOption -...
0
votes
0
answers
19
views
Pasting deleted text in Powershell 7
I'm trying to add my favorite keyboard shortcuts from Linux/Bash to PowerShell to make it easier to switch between them (see code snippet below and you'll get the idea). Though there is one feature I'...
3
votes
1
answer
39
views
Format timer.elapsed for write-host
$timer = [System.Diagnostics.Stopwatch]::StartNew()
Start-Sleep -Second 83
$timer.stop
$elapsed=$timer.elapsed
Write-Host $elapsed < Works, but not shown in desired ...
1
vote
1
answer
76
views
How to limit exported commands from binary powershell module (*.dll file)?
I know I can limit exported commands from module that is imported like this:
Import-Module C:\...\MyModule or Import-Module C:\...\MyModule\MyModule.psd1
Then I can use CmdletsToExport in .psd1.
But, ...
0
votes
1
answer
65
views
Split behaviour changes when script is run with PS2EXE
If I run this code as a ps1-file in the console it gives the expected output, but if I 'compile' the script with PS2EXE there's no second part of the string:
$a = "first Part`r`n`r`nsecond Part&...
2
votes
1
answer
342
views
Powershell 7: Issue with Where-Object and tags
I am running a simple powershell query in Azure. I am looking to filter only the Web Apps with a certain Tag assigned to it:
$apps = Get-AzWebApp | Where-Object {$_.Tags["Application"] -...
-1
votes
1
answer
137
views
What is the fastest way to extract data from SQL Server 2005 using PowerShell 7?
This is not just a simple extraction.
I have two tables. I take the values from one table and then use one column from this table to find a corresponding value in another table and then extract all ...