When migrating your BizTalk Server environment or deploy 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. That you should do it or not, this is not the goal, only that this 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, which 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.
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"
THIS POWERSHELL IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND.
Extract a folder structure and automatically generate a PowerShell script to recreate the folder scturure on a different server with PowerShell
GitHub