Recreating local folder structure with PowerShell

Posted: December 20, 2020  |  Categories: Administration BizTalk Deployment PowerShell
Tags:

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 PowerShellExtract a folder structure and automatically generate a PowerShell script to recreate the folder scturure on a different server with PowerShell
GitHub

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

Leave a Reply

Your email address will not be published. Required fields are marked *

BizTalk360
BizTalk Server

Over 500+ customers across
30+ countries depend on BizTalk360

Learn More
Serverless360
Azure

Manage and monitor serverless
components effortlessly

Learn More
Atomicscope
Business Users

Monitor your Business Activity in iPaaS
or Hybrid integration solutions

Learn More

Back to Top