{"id":1165,"date":"2016-12-15T13:33:20","date_gmt":"2016-12-15T12:33:20","guid":{"rendered":"http:\/\/blogs.msdn.microsoft.com\/lavanack\/?p=1165"},"modified":"2022-05-30T13:52:05","modified_gmt":"2022-05-30T11:52:05","slug":"workflow-parallel-lastwritetime","status":"publish","type":"post","link":"https:\/\/laurentvanacker.com\/index.php\/2016\/12\/15\/workflow-parallel-lastwritetime\/","title":{"rendered":"Modification de la date d&rsquo;\u00e9criture d&rsquo;un fichier sur un ensemble de serveurs en parall\u00e8le \/ Changing the last write time of a file on a set of servers using a parallel processing"},"content":{"rendered":"<div id=\"fr-FR\" align=\"justify\"><a href=\"#en-US\">Go to English version<\/a><\/div>\n<div align=\"justify\"><\/div>\n<div align=\"justify\">Lors d&rsquo;une de mes sessions de formation PowerShell, un client m&rsquo;a demand\u00e9 la possibilit\u00e9 de modifier la date de derni\u00e8re \u00e9criture d&rsquo;un fichier sur un ensemble de serveurs (pour des probl\u00e9matiques de backup) en parall\u00e8le (pour des raisons de performance). Les workflows PowerShell permettent justement d&rsquo;effectuer des t\u00e2ches en parall\u00e8le. Apr\u00e8s plusieurs tentatives de scripts infructueuses, j&rsquo;ai abouti au script suivant (assez simple au prime abord &#8211; Le code source est disponible <a href=\"https:\/\/github.com\/lavanack\/laurentvanacker.com\/blob\/master\/Windows%20Powershell\/Windows\/Misc\/Set-LastWriteTime-WF.ps1\" target=\"_blank\" rel=\"noopener noreferrer\">ici<\/a>) :<\/div>\n<div align=\"justify\"><\/div>\n<div align=\"justify\">\n<pre class=\"brush: powershell; collapse: true; light: false; title: ; toolbar: true; notranslate\" title=\"\"> #requires -version 3\r\nworkflow Set-LastWriteTime-WF\r\n{\r\n&#x5B;CmdletBinding()] Param( &#x5B;String&#x5B;]]$Computers, &#x5B;String]$FullName, &#x5B;Datetime]$LastWriteTime ) foreach -parallel($Computer in $Computers)\r\n{\r\nSet-ItemProperty -Path $FullName -Name LastWriteTime -Value $LastWriteTime -PSComputerName $Computer\r\n}\r\n}\r\nClear-Host $Computers = '2012R2-MS', '2012R2-DC', 'WIN8-WS'\r\nSet-LastWriteTime-WF -Computers $Computers -FullName 'C:\\Windows\\WindowsUpdate.log' -LastWriteTime $(Get-Date) -Verbose \r\n<\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/laurentvanacker.com\/wp-content\/uploads\/2017\/01\/012717_1333_Fusionnerde1.png\" alt=\"\" \/><\/p>\n<p>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 &#8211; The source code is <a href=\"https:\/\/github.com\/lavanack\/laurentvanacker.com\/blob\/master\/Windows%20Powershell\/Windows\/Misc\/Set-LastWriteTime-WF.ps1\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>)<\/p>\n<pre class=\"brush: powershell; collapse: true; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n#requires -version 3 \r\nworkflow Set-LastWriteTime-WF \r\n{\r\n    &#x5B;CmdletBinding()] Param( &#x5B;String&#x5B;]]$Computers, &#x5B;String]$FullName, &#x5B;Datetime]$LastWriteTime ) foreach -parallel($Computer in $Computers) \r\n    {\r\n        Set-ItemProperty -Path $FullName -Name LastWriteTime -Value $LastWriteTime -PSComputerName $Computer\r\n    } \r\n} \r\nClear-Host $Computers = '2012R2-MS', '2012R2-DC', 'WIN8-WS' \r\nSet-LastWriteTime-WF -Computers $Computers -FullName 'C:\\Windows\\WindowsUpdate.log' -LastWriteTime $(Get-Date) -Verbose\r\n<\/pre>\n<p>Laurent.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Go to English version Lors d&rsquo;une de mes sessions de formation PowerShell, un client m&rsquo;a demand\u00e9 la possibilit\u00e9 de modifier la date de derni\u00e8re \u00e9criture [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":2463,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,11],"tags":[39],"class_list":["post-1165","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","category-scripting","tag-powershell"],"_links":{"self":[{"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/posts\/1165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/comments?post=1165"}],"version-history":[{"count":17,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/posts\/1165\/revisions"}],"predecessor-version":[{"id":2880,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/posts\/1165\/revisions\/2880"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/media\/2463"}],"wp:attachment":[{"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/media?parent=1165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/categories?post=1165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laurentvanacker.com\/index.php\/wp-json\/wp\/v2\/tags?post=1165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}