thuelsing.de THUELSING.DE

Techstuff, programming and galleries

Powershell

I'll collect a few useful  powershell commands here I used to google every other month. Perhaps, it helps other people. If you know more, just wriite me.

Replace string in many files:

To replace a string, e.g. a wrong date stamp, use the command below and you'll replace "xxx" with "yyy" in all files in pwd.

dir | rename-item -NewName {$_.name -replace "xxx","yyy"}

Flatten directory

In some cases, you want to move all files recursively from directory <from>  to directory <to>. This can be done with:

Get-ChildItem <from> -Recurse -File | Move-Item -destination <to>