PowerShell Performance: Avoiding the pipeline part 1

The PowerShell pipeline is a practial tool in the shell. But if you are writing scripts or workflows, avoid the pipeline! It will increase the running time of your script/workflow.

Run to following script on your machine to see the difference:

On my machine, the operation with the foreach-object (pipeline) took 4.7s longer than a simple foreach.

Another advantage is the readability of your code: while using the pipeline, the name of the control variable is given ($_), you can choose a meaningful name in a simple foreach (e.g. foreach ($process in Get-Process)).

Synology Audio Station – Recently Added

After the upgrade to Synology DSM 6 I noticed that the “Recently Added” section in the Audio Station was messed up. First I tried to reindex the whole library, but this didn’t do the trick. After a short glance in the Synology forum, I found out that the problem was due to the “created on” date of the music files. I deceided to fix this problem with the help of mighty powershell:
Get-ChildItem -Path "\\server\share\music\" -Recurse | ForEach-Object {if ($_.CreationTime -gt (Get-Date)) {$_.CreationTime = $_.LastWriteTime}}
Don’t forget to replace the path to your music folder. What does this simple one-liner do? It checks all elements under the given path if the “Creation Time” property is greater than the current date. If this is the case, it will replace the “Creation Time” with the “LastWriteTime”.

Run the indexing service afterwards (Control Panel -> Indexing Service -> Re-Index).


Synology Wake-on-lan (without additional packages)

A couple of years ago, there was a Synology package provided by Axl to easily wake a computer in your LAN from the Synology NAS. However, after a few DSM updates, the package wasn’t working anymore. So George Ruinelli took Axls package, enhanced it and life was good again. Just until Synology updated DSM again and the package from George was working neither. Unfortunately, the support was discontinued, so I had to keep my eyes open for another solution. And I found this one:

Synology introduced a feature in DSM 4.2 called the Task Scheduler! Since ether-wake (or synonet on DSM 6 or higher) is already installed, simply create a task to wake your computer and run it when you need to wake it up. No additional packages or software needed!

To create such a task go into the “Control Panel” and open the “Task Scheduler”. Create a new scheduled task (user-defined script):


Enter a name for the task and select “root” as user to run the task:


In the “Schedule” tab, select a past date in case you don’t want to run the task right now:


In the “Task Settings” tab enter the command line to start your computer:


DSM 6.0 or higher:
synonet --wake XX:XX:XX:XX:XX:XX eth0
DSM 5.2 or lower:
ether-wake -i eth0 XX:XX:XX:XX:XX:XX
Don’t forget to change the MAC Address and the network interface (in case you have multiple network interfaces). Click OK to create the task.

Once created, you can run the task whenever you want to by right clicking it and selecting “Run”: