When migrating your BizTalk Server environment or deploying to a new or different environment, there are many different resources or configurations that you need to take into considerations like:
- Local queue creations.
- Cloud queue creations.
- Folder creations.
- And so on.
One of the common resources that we use on our integration solutions is local folders, whether for archiving or routing messages. I do not mean that it is a good practice or not. Whether you should do it or not, this is not the goal, only that it is common to happen.
In a first analysis, we could think that the quickest and most effective solution would be to copy and paste the folder structure from one environment to another. Still, it may not be the best solution in many cases since it may contain thousands of documents that are unnecessary to copy/migrate.
This blog post will address how we can easily recreate a folder structure in a different environment/server using PowerShell.
📝 One-Minute Brief
Shows how to recreate an existing local folder structure using PowerShell by generating a script that rebuilds directories on a different server or environment without copying unnecessary files.
PowerShell script to recreate a local folder structure
With this PowerShell sample, we will be able to recreate an existing local folder structure on a different BizTalk Server environment.
$folderList = Get-ChildItem -Path $path -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object FullName
foreach ($folder in $folderList)
{
$powerShellCommand = 'New-Item -ItemType Directory -Path "'+$folder.FullName+'"'
Add-Content -Path $scriptPath -Value $powerShellCommand
}
The output of this PowerShell script will be a creation of a different PS script containing the instructions that you can use to recreate all the folder structures in different environments.
New-Item -ItemType Directory -Path "D:\BiztalkFilePorts\APP1"
New-Item -ItemType Directory -Path "D:\BiztalkFilePorts\APP2"
New-Item -ItemType Directory -Path "D:\BiztalkFilePorts\APP3\Inbox"
New-Item -ItemType Directory -Path "D:\BiztalkFilePorts\APP3\Outbox"
New-Item -ItemType Directory -Path "D:\BiztalkFilePorts\APP3\Outbox\FLD1"
New-Item -ItemType Directory -Path "D:\BiztalkFilePorts\APP3\Outbox\FLD2"
New-Item -ItemType Directory -Path "D:\BiztalkFilePorts\APP4\Inbox"
New-Item -ItemType Directory -Path "D:\BiztalkFilePorts\APP4\Outbox"
Download
THIS POWERSHELL IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND.
You can find this PowerShell script on GitHub:
Hope you find this helpful! If you liked the content or found it useful and would like to support me in writing more, consider buying (or helping to buy) a Star Wars Lego set for my son.