Thursday, March 1, 2018

Parallel File Copy using Powershell Workflow!



Long Time No See!!😁😁😁😁😁😁

Due to my busy  schedule, I am not able to post or update the blogs but recently someone asked me about concept of Powershell Workflow and we have good discussions on how it is helpful and it was proved that powershell is no less than any language which endure all the requirement a sysadmin can have.

Starting with Powershell Workflow, Let's imagine that you need to perform the following tasks on a fleet of 12 new servers:
  1. Set hostname (and reboot).
  1. Join Active Directory (AD) domain (and reboot).
  1. Enumerate all installed .dll files and copy an output file to a network share
Microsoft added the Windows Workflow Foundation (WF) engine to version 3.0 of the .NET Framework. It brings a cool set of functionalities such as the possibilities to execute code in parallel, to create scripts that are persist to reboot, and lot’s of other neat things.
To understand more, please go to basics of workflow with below link:


Here is my implementation of Powershell Workflow:

We need to copy file in multiple servers, but Copy-Item will copy one file on server at a time. This is where Workflow Parallel functionality.
--------------------------------------------------------------------------------------------------------------------------# Name - Copy-File-v4.ps1
# Created - Visual Code
# Modified - 27-02-2018
# Description - Will copy parallel software to multiple server and create report about status
Workflow Start-Copy
{
    param ([string[]]$server)
    # 20 is thread Parallel, we can increase decrease depending on size and memory of server where script is running!
     Foreach -parallel -throttle 20 ($ShareM in $server)
     {
        sequence{
        if(test-path -Path "\\$s\Software\Utility"){
         Copy-Item  "E:\Script\Distribution\Winzip.zip"  "\\$ShareM\Software\Utility"  -Verbose -ErrorAction SilentlyContinue
         Get-Item "\\$ShareM\Software\Utility\Winzip.zip" -Verbose | Select-Object Name,length,FullName | Export-csv -Path C:\temp\WinzipDist.csv -Append -NoTypeInformation
            }
         }
     }
}
# ServerName is input file where we mentioned servers to copy files
$Entry=Get-Content -path E:\Script\Distribution\ServerName.txt
# Calling Workflow function Start-Copy
Start-Copy -server $Entry
--------------------------------------------------------------------------------------------------------------------------
Please comment in case, you have any issue or doubt regarding same!
SayoNara!





No comments:

Post a Comment

Windows Server 2016 Key Features and License Prospects

If you are planning to move to Windows 2016 and looking for benefits, I have listed down below : Why Windows Server 2016? ·     ...