Modification de la date d’écriture d’un fichier sur un ensemble de serveurs en parallèle / Changing the last write time of a file on a set of servers using a parallel processing

Lors d’une de mes sessions de formation PowerShell, un client m’a demandé la possibilité de modifier la date de dernière écriture d’un fichier sur un ensemble de serveurs (pour des problématiques de backup) en parallèle (pour des raisons de performance). Les workflows PowerShell permettent justement d’effectuer des tâches en parallèle. Après plusieurs tentatives de scripts infructueuses, j’ai abouti au script suivant (assez simple au prime abord – Le code source est disponible ici) :
 #requires -version 3
workflow Set-LastWriteTime-WF
{
[CmdletBinding()] Param( [String[]]$Computers, [String]$FullName, [Datetime]$LastWriteTime ) foreach -parallel($Computer in $Computers)
{
Set-ItemProperty -Path $FullName -Name LastWriteTime -Value $LastWriteTime -PSComputerName $Computer
}
}
Clear-Host $Computers = '2012R2-MS', '2012R2-DC', 'WIN8-WS'
Set-LastWriteTime-WF -Computers $Computers -FullName 'C:\Windows\WindowsUpdate.log' -LastWriteTime $(Get-Date) -Verbose 

In one of my PowerShell training sessions, a client asked me to change the last write time of a given file on a set of servers (for backup reasons) in parallel way (for performance reasons ). PowerShell workflows allow you to do that. After several attempts of unsuccessful scripts, I wrote to the following script (simple enough at first glance – The source code is here)

#requires -version 3 
workflow Set-LastWriteTime-WF 
{
    [CmdletBinding()] Param( [String[]]$Computers, [String]$FullName, [Datetime]$LastWriteTime ) foreach -parallel($Computer in $Computers) 
    {
        Set-ItemProperty -Path $FullName -Name LastWriteTime -Value $LastWriteTime -PSComputerName $Computer
    } 
} 
Clear-Host $Computers = '2012R2-MS', '2012R2-DC', 'WIN8-WS' 
Set-LastWriteTime-WF -Computers $Computers -FullName 'C:\Windows\WindowsUpdate.log' -LastWriteTime $(Get-Date) -Verbose

Laurent.

Feel free to share:)