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:
- Set hostname (and reboot).
- Join Active Directory (AD) domain (and reboot).
- Enumerate all installed .dll files and copy an output file to a network share
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
--------------------------------------------------------------------------------------------------------------------------# 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