In this blog post we are going to learn a very simple Power Shell script to create folder structure to store our report in SharePoint.
Background :So, recently I was doing migration from SharePoint 2010 to SharePoint online using ShareGate script and in which I need to create a folder structure to store different reports.
So what we are going to do here with a small Power Shell script ,going to create a folder structure in our machine drive.
Procedure: We have URL lists of SharePoint 2010 sites and already created SharePoint site collection lists to migrate content.
So what we did we split SharePoint online sites URL after /sites/ with the help of excel as in our scnerio we are using excel to store SRC and destination site
Ex.
https://abc.sharepoint.com/sites/Site1
After splitting it with the help of excel formula we get only Site1 in a cell and we store it in a csv.
So if we have 10 sites to migrate our csv file (opened in notepad)

So now we’re going to create a folder structure where we must create a folder structure like every name (from CSV file) should contain 4 more folders to store Migration Reports, QC Reports, CheckedOut Document and Workflow Reports.
#Base Location where we want to create our folder structure
$BaseLocation = "C:\SPMigrationReports\"
#get today's date where we are going to create folder structure
$todaysDate=Get-Date -Format ddMMyyyy
$RootLocation=$BaseLocation+$todaysDate
#Read data from CSV file
$Folders = Import-Csv C:\Users\Vipin\Documents\FolderStructure.csv
#collection of four mandatory folders
$subFolders=@("CheckedOut Documents","Migration Reports","QC Reports","Workflow Reports")
#Main logic to create folder structure.
ForEach ($Folder in $Folders) {
foreach($subfolder in $subFolders){
New-Item -Path @("$RootLocation\"+$Folder.Name) -Name $subfolder -type directory
}
}
After successfully running the script we get the folder structure like below.

Feel free to ask questions😊