Public/Get-MigrationString.ps1

Function Get-MigrationString {
    <#
.SYNOPSIS
    Creates the string to begin the migration of a PST from the blob storage.

.DESCRIPTION
    Automates the process of building migration requests of PSTs.

.EXAMPLE
    The example below does blah
    PS C:\> <Example>
    
.NOTES
    Author: Jesse Newell
    Last Edit: 2019-10-18
    Version 1.0 - Initial release of Get-MigrationString - 11/15/2018
    Version 1.1 - Update for module function. 10/18/2019

#>


    [CmdletBinding()]
    Param (
        
        [Parameter (Mandatory = $True, ValueFromPipeline = $True)]
        [psobject[]]$Params
        
    )

    Begin { 
        #Get PST CSV file
        Write-Host "Locate and insert the PSTImportMapping.CSv for the group of PSTs"
        $ImportFile = Get-FileName -initialDirectory "c:fso" 

        Write-Host "Insert the Shared Access Signature token." -NoNewLine
        Write-Host " Check behind the Powershell Console if you don't see it!" -ForegroundColor Yellow

        Get-SasDialog

        #SharedAccessSignature Query String
        $AzureSharedAccessSignatureToken, $isArchive, $TextBoxPrefix = Get-SasDialog

        $PSTFiles = Import-Csv $ImportFile

    }

    Process { 
        # Truncates the TargetRootPath to a shorter version to just include OutlookFiles/PSTName
        foreach ($pstFile in $pstFiles) {
            $targetroot = $($pstFile.targetrootfolder)
            $charCount = ($targetroot.ToCharArray() | Where-Object { $_ -eq '/' } | Measure-Object).Count
            $pstName = ($targetroot -split '/')[$charCount].Substring(0)
            $pstPath = "Imported/$pstName"
            If ($isArchive) {
                $PSTFile | ForEach-Object {
                    $Params = @{
                        Name                            = $_.Name
                        Mailbox                         = $_.Mailbox
                        TargetRootFolder                = $pstPath
                        BadItemLimit                    = 25 
                        AzureBlobStorageAccountUri      = $_.FilePath
                        AzureSharedAccessSignatureToken = $AzureSharedAccessSignatureToken
                        IsArchive                       = $True
                    }
                }
            }
            else {
                $PSTFile | ForEach-Object {
                    $Params = @{
                        Name                            = $_.Name
                        Mailbox                         = $_.Mailbox
                        TargetRootFolder                = $pstPath
                        BadItemLimit                    = 25 
                        AzureBlobStorageAccountUri      = $_.FilePath
                        AzureSharedAccessSignatureToken = $AzureSharedAccessSignatureToken
                    }
                }
            }
        }
    }

    End {
        Write-Host "Select the PSTs you would like to import. Control+A to select all, then press OK"
        $Params | out-gridview -PassThru

        #Text file is placed in your working directory.
        $Params | Out-File "$($ScriptItem.DirectoryName)\PSTImports_$(Get-Date -Format MM-dd-yyyy_hh-mm-tt).txt"

        Write-Host "Success" -ForegroundColor White -BackgroundColor Green
        Write-Host "The commands you selected have been exported to a text document called" -NoNewline 
        Write-Host " PSTImports_$(Get-Date -Format MM-dd-yyyy_hh-mm-tt).txt, located in $($ScriptItem.DirectoryName)" -ForegroundColor Green
    }
}