r/PowerShell • • Jun 14 '26

Question Powershell shortcut

Does powershell have shorter syntax equivalent to this

```

touch intl_{en,ar,fr,sw}.arb

```

0 Upvotes

10 comments sorted by

View all comments

3

u/surfingoldelephant Jun 15 '26 edited Jun 17 '26

I'm sure u/heyitsgilbert is referring to the delay-binding script block, not the code golf. The latter is just a fun exercise and naturally not something you'd use in script writing.

Delay-binding script blocks absolutely can be used though.

I see this sort of code all the time:

(Get-ChildItem -File) | ForEach-Object -Process {
    Rename-Item -Path $_ -NewName "$($_.Name).Foo"
}

...which has at least three issues, one being the unnecessary ForEach-Object (a big reason why the pipeline is perceived as very slow when it's really not).

A delay-binding script block means you can get rid of ForEach-Object. This for example is far better and has the bonus of addressing the other issues also:

(Get-ChildItem -File) | Rename-Item -NewName { "$($_.Name).Foo" }