DFS Client-Matter Folder Creation Tool

A Tool To Create DFS Folders And Security

                        
                            #Created by Doug Suyemoto
                            #DFS Client-Matter Folder Creation

                            #region CONSTANTS
                            $csScriptName = 'DFS Client-Matter Folder Creation'
                            $csVersion = "5.1.1.1"

                            # Log Path
                            $csLogPath = ""

                            #Email that receives error messages
                            $global:serviceAccountEmailAddress = ""

                            #Email settings when Folder Permissions incorrect
                            $sTempFolder = $Env:TEMP
                            $csSubject = "Please correct Client-Matter Folder Permissions"
                            $sLegalHoldBodyFilePath = "$sTempFolder\legalHold.txt"
                            $csSmtpEmailServer = ""

                            #Email settings when inconsistent permissions detected
                            $csInconsistentPermissionsEmailAddress = ""
                            #Text included in email when sent on errors
                            $csErrorFormText = "Permissions on this client-matter are inconsistent or incorrect. "
                            #Text included in email when sent on additional permissions found
                            $csAdditionalPermissionsDefaultText = "Errors were found when creating/modifying DFS Folders:`n`n"
                            #Add offices to exclude for checking for additional permissions
                            $arrOfficePermissionExclusion = "", "", ""

                            # Assign default security objects
                                
                                #Access for Support Services (Full Access)
                                $global:objSupportServicesClientAccess = New-Object PSObject -Property @{ 
                                    FileSystemRights  = "ReadAndExecute, Synchronize"
                                    AccessControlType = "Allow"
                                    IdentityReference = "TEST\SupportServices"
                                    IsInherited = $False
                                    InheritanceFlags = "None"
                                    PropagationFlags = "NoPropagateInherit"		
                                    }
                                $global:objSupportServicesDataMatterAccess = New-Object PSObject -Property @{
                                    FileSystemRights  = "FullControl"
                                    AccessControlType = "Allow"
                                    IdentityReference = "TEST\SupportServices"
                                    IsInherited = $False
                                    InheritanceFlags = "ContainerInherit, ObjectInherit"
                                    PropagationFlags = "None"
                                    }
                                $global:objSupportServicesImagesMatterAccess = New-Object PSObject -Property @{
                                    FileSystemRights  = "FullControl"
                                    AccessControlType = "Allow"
                                    IdentityReference = "TEST\SupportServices"
                                    IsInherited = $False
                                    InheritanceFlags = "ContainerInherit, ObjectInherit"
                                    PropagationFlags = "None"
                                    }
                                #Client Group Access
                                $global:objGroupClientAccess = New-Object PSObject -Property @{ 
                                    FileSystemRights  = "ReadAndExecute, Synchronize"
                                    AccessControlType = "Allow"
                                    IdentityReference = "TEST\$strShareClientGroup"
                                    IsInherited = $False
                                    InheritanceFlags = "None"
                                    PropagationFlags = "NoPropagateInherit"	
                                    }
                                #Matter Group Access
                                $global:objGroupDataMatterAccess = New-Object PSObject -Property @{ 
                                    FileSystemRights  = "FullControl"
                                    AccessControlType = "Allow"
                                    IdentityReference = "TEST\$strShareMatterGroup"
                                    IsInherited = $False
                                    InheritanceFlags = "ContainerInherit, ObjectInherit"
                                    PropagationFlags = "None"
                                    }
                                $global:objGroupImagesMatterAccess = New-Object PSObject -Property @{ 
                                    FileSystemRights  = "ReadAndExecute, Synchronize"
                                    AccessControlType = "Allow"
                                    IdentityReference = "TEST\$strShareMatterGroup"
                                    IsInherited = $False
                                    InheritanceFlags = "ContainerInherit, ObjectInherit"
                                    PropagationFlags = "None"	
                                    }
                                #Default Administrator Access
                                $global:objLocalAdministratorsAccess = New-Object PSObject -Property @{
                                    FileSystemRights  = "FullControl"
                                    AccessControlType = "Allow"
                                    IdentityReference = "$BUILTIN\Administrators"
                                    IsInherited = $False
                                    InheritanceFlags = "ContainerInherit, ObjectInherit"
                                    PropagationFlags = "None"
                                    }
                                $global:objSystemAccess = New-Object PSObject -Property @{
                                    FileSystemRights  = "FullControl"
                                    AccessControlType = "Allow"
                                    IdentityReference = "$NTAUTHORITY\SYSTEM"
                                    IsInherited = $False
                                    InheritanceFlags = "ContainerInherit, ObjectInherit"
                                    PropagationFlags = "None"
                                    }


                            # $global:arrOffice is the top level Office OU
                            $global:arrOffice = "Office1", "Office2", "Office3"

                            # $global:hOffice is the hash table where the KEY is the office and VALUE is the OU
                            # where the groups are to be created and has the following LDAP 
                            # Distinguished name: 'ou=VALUE, ou=KEY, dc=test, dc=com'
                            $global:hOffice = @{ Office1="GroupFolder1" 
                                                Office2="GroupFolder2"
                                                Office3="GroupFolder3" }

                            $arrOfficeUS = "TestUS"
                            $arrOfficeEuro = "TestEuro"
                            $arrOfficeAsia = "TestAsia"
                            $arrOfficeDE = "TestDE"
                            $aShareServerLocations = "serverUS", "serverEurope", "serverASIA"
                            $csGroupOUUS = "PracticeSupport"
                            $csGroupOUEurope = "SupportServices"
                            $csGroupOUAsia = "SupportServices"
                            #endregion

                            #region Get Group OU from Office OU
                            function GetOfficeGroupOU($sOfficeOU) {
                                return $global:hOffice[$sOfficeOU]
                            }
                            #endregion

                            #region MsgBox Function
                            # See http://msdn.microsoft.com/en-us/library/x83z1d9f(v=vs.84).aspx for options
                            function messageBox ($strMessage,$intMessage,$strTitle,$intButton) {
                                $msgBox = new-object -comobject wscript.shell
                                $response = $msgBox.popup($strMessage,$intMessage,$strTitle,$intButton)
                                if($response -eq 2) { break } # Cancel
                                if($response -eq 7) { break } # No
                            }
                            #endregion

                            #region Logging
                            if ((Test-Path $csLogPath) -eq $false) { New-Item -Path $csLogPath -ItemType Directory }
                            $sLogFolder = $(Get-Date -Format "yyyy-MM-dd")
                            $sLogFolderPath = "$csLogPath\$slogFolder"
                            $slogFilePath = "$slogFolderPath\$(([guid]::NewGuid()).Guid).txt"
                            Write-Host "Log file path = $slogFilePath"
                            $csDateTimeFormat = "yyyy-MM-dd hh:mm:ss"

                            # Write to file
                            function writeToFile($dateTime,$sMsg,$sType,$sLocation) {   
                                if ((Test-Path $sLogFolderPath) -eq $False) { New-Item -Path $sLogFolderPath -ItemType Directory }
                                if ((Test-Path $sLogFilePath) -eq $False) { New-Item -Path $sLogFilePath -ItemType File }
                                Add-Content -Path $sLogFilePath -Value "$dateTime,$sLocation,$sType,$sMsg"
                            }

                            # Post Log
                            function postLog($sLocation,$sLogInfo,$sType) {   
                                $dateTime = Get-Date -Format $csDateTimeFormat
                                writeToFile "$dateTime" "$sLogInfo" "$sType" "$sLocation" | Out-Null
                                Write-Host "$dateTime $sLocation : $sLogInfo"
                            }

                            # $sLogInfo is message, $sType is of [DEBUG, INFO, WARNING, ERROR], $sLocation is the origin in script
                            function postLog2([string]$sLogInfo, [string]$sType, [string]$sLocation) {
                                if (-not $sLocation) { $sLocation = "root" }
                                if (-not $sType) { $Type = "INFO" }
                                $dateTime = Get-Date -Format $csDateTimeFormat
                                writeToFile "$dateTime" "$sLogInfo" "$($sType.Upper())" "$sLocation" | Out-Null
                                Write-Host "$dateTime $sLocation : $sLogInfo"
                                if ($sType.Upper() -eq "ERROR") { $Error.Clear() }
                            }

                            function postLog($sMsg,$sType) {
                                $sLocation = "root"
                                $aMsg = $sMsg.Split(":")
                                        if ($aMsg.Count -gt 1) {
                                            $sLocation = $aMsg[0].Trim()
                                            $sLogInfo = $aMsg[1].Trim()
                                        } else {
                                            $sLogInfo = $sMsg
                                        }
                                $dateTime = Get-Date -Format $csDateTimeFormat
                                writeToFile "$dateTime" "$sLogInfo" "$sType" "$sLocation" | Out-Null
                                Write-Host "$dateTime $sLocation : $sLogInfo"
                            }

                            # Post Status
                            function postStatus($strMsg,$strType) {
                                $statusBar1.Text = $strMsg
                                postLog2 "$strMsg" "$strType"
                            }
                            function postStatus($sLocation,$sLogInfo,$sType) {
                                if ($slocation -ne "" -and $sLogInfo -ne "" -and $sType -ne "") {
                                    $statusBar1.Text = "$slocation : $sLogInfo"
                                    postLog2 "$sLogInfo" "$sType" "$slocation" 
                                }
                            }
                            function postStatus(
                                [string]$sLocation,
                                [string]$sLogInfo,
                                [string]$sType, 
                                [System.Windows.Forms.StatusBar]$fStatusBar) {

                                if ($fStatusBar) {
                                    $fStatusBar.Text = "$slocation : $sLogInfo"
                                    postLog2 "$sLogInfo" "$sType" "$slocation"
                                }
                            }

                            #region Decrypt Service Account
                            function retrieveServiceAccount {
                                postLog2 "Retrieving service account..."
                                
                                #CODE TO RETRIEVE SERVICE ACCOUNT

                                #return New-Object -TypeName System.Management.Automation.PSCredential("username", $securepassword)
                            }
                            #endregion

                            #region Get Office of User Running Script
                            function getUserOffice([string]$UserName) {
                                try {
                                    postLog2 "$UserName" "DEBUG" "getUserOffice"
                                    $objUsername = Get-ADUser $UserName -Credential $global:serviceCredentials
                                    postLog2 "Username=$($objUsername.Name)" "DEBUG" "getUserOffice"
                                    if ($objUsername.Name -match '\s*[\w\.\-]+, [\w\.\-]+ \(([\w]+)[\w \-]*\)') {
                                        $sUserOffice = $Matches.1
                                    }
                                    postLog2 "$sUserOffice" "DEBUG" "getUserOffice"
                                    
                                    return $sUserOffice
                                } catch [System.Exception] { postLog2 "$Error" "ERROR" "getUserOffice" }
                            }
                            #endregion

                            #region Test-path with credentials
                            function testPath([string]$strTestPath) {
                                if ($strTestPath) {
                                    $strTestResult = Test-Path $strTestPath
                                    Write-Output $strTestResult
                                }
                            }
                            #endregion

                            #region Email Notification
                            function emailNotification ($sUserEmailAddress, $sEmailTo, $sBody, $sSubject, $sServer) {
                                postStatus "Sending email notification..." "INFO"
                                try {
                                    $smtpClient = New-Object Net.Mail.SmtpClient($sServer)
                                    $smtpClient.EnableSsl = $True
                                    $smtpClient.Credentials = $global:serviceCredentials.GetNetworkCredential()
                                    $sbody = "Notification sent from $sUserEmailAddress`r`n`r`n$sbody"
                                    $smtpClient.Send($global:serviceAccountEmailAddress, $sEmailTo, $sSubject, $sBody)        
                                    postLog2 "Sending email notification complete!" "INFO"
                                } catch [System.Exception] { 
                                    postLog2 "$Error" "ERROR" "emailNotification"
                                }
                            }
                            #endregion

                            #region Error Form for incorrect permissions
                            function ErrorForm {
                            ########################################################################
                            # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
                            # Generated On: 4/11/2012 5:46 PM
                            # Generated By: dsuyemot
                            ########################################################################

                            #region Import the Assemblies
                            [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
                            [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
                            #endregion

                            #region Generated Form Objects
                            $ErrorForm = New-Object System.Windows.Forms.Form
                            $errorFormCancelButton = New-Object System.Windows.Forms.Button
                            $detailsLabel = New-Object System.Windows.Forms.Label
                            $OKbutton = New-Object System.Windows.Forms.Button
                            $notificationGroupBox = New-Object System.Windows.Forms.GroupBox
                            $emailToTextBox = New-Object System.Windows.Forms.TextBox
                            $emailToLabel = New-Object System.Windows.Forms.Label
                            $errorRichTextBox = New-Object System.Windows.Forms.RichTextBox
                            $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
                            #endregion Generated Form Objects

                            #----------------------------------------------
                            #Generated Event Script Blocks
                            #----------------------------------------------
                            #Provide Custom Code for events specified in PrimalForms.
                            $handler_MessageForm1_Load= 
                            {
                            #	$cancelButton.enabled = $True
                                if (Test-Path $sLegalHoldBodyFilePath) { 

                                    Get-Content -Path $sLegalHoldBodyFilePath | % { $oDetailsText = $oDetailsText + "`n$_" }

                                    $errorRichTextBox.Text = $oDetailsText
                                    $errorRichTextBox.Select(0,$csErrorFormText.Length)
                                }
                            }

                            $OKbutton_OnClick= 
                            {
                                $OKbutton.Enabled = $False
                                $ErrorForm.Close()
                            }

                            $errorFormCancelButton_OnClick= 
                            {
                            #	$cancelButton.enabled = $True
                                $ErrorForm.Close()
                            }

                            $OnLoadForm_StateCorrection=
                            {#Correct the initial state of the form to prevent the .Net maximized form issue
                                $ErrorForm.WindowState = $InitialFormWindowState
                            }

                            #----------------------------------------------
                            #region Generated Form Code
                            $ErrorForm.AutoSizeMode = 0
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 623
                            $System_Drawing_Size.Width = 682
                            $ErrorForm.ClientSize = $System_Drawing_Size
                            $ErrorForm.DataBindings.DefaultDataSourceUpdateMode = 0
                            $ErrorForm.Font = New-Object System.Drawing.Font("Arial",9,0,3,1)
                            $ErrorForm.Name = "ErrorForm"
                            $ErrorForm.Text = "Incorrect Folder Permissions Detected!"
                            $ErrorForm.add_Load($handler_MessageForm1_Load)

                            $errorFormCancelButton.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 567
                            $System_Drawing_Point.Y = 570
                            $errorFormCancelButton.Location = $System_Drawing_Point
                            $errorFormCancelButton.Name = "errorFormCancelButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 24
                            $System_Drawing_Size.Width = 75
                            $errorFormCancelButton.Size = $System_Drawing_Size
                            $errorFormCancelButton.TabIndex = 10
                            $errorFormCancelButton.Text = "Cancel"
                            $errorFormCancelButton.UseVisualStyleBackColor = $True
                            $errorFormCancelButton.add_Click($errorFormCancelButton_OnClick)
                            $ErrorForm.Controls.Add($errorFormCancelButton)

                            $detailsLabel.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 18
                            $detailsLabel.Location = $System_Drawing_Point
                            $detailsLabel.Name = "detailsLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 16
                            $System_Drawing_Size.Width = 56
                            $detailsLabel.Size = $System_Drawing_Size
                            $detailsLabel.TabIndex = 9
                            $detailsLabel.Text = "Details:"
                            $detailsLabel.add_Click($handler_label3_Click)
                            $ErrorForm.Controls.Add($detailsLabel)


                            $OKbutton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 567
                            $System_Drawing_Point.Y = 540
                            $OKbutton.Location = $System_Drawing_Point
                            $OKbutton.Name = "OKbutton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 24
                            $System_Drawing_Size.Width = 75
                            $OKbutton.Size = $System_Drawing_Size
                            $OKbutton.TabIndex = 1
                            $OKbutton.Text = "OK"
                            $OKbutton.UseVisualStyleBackColor = $True
                            $OKbutton.add_Click($OKbutton_OnClick)

                            $ErrorForm.Controls.Add($OKbutton)


                            $notificationGroupBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 22
                            $System_Drawing_Point.Y = 523
                            $notificationGroupBox.Location = $System_Drawing_Point
                            $notificationGroupBox.Name = "notificationGroupBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 84
                            $System_Drawing_Size.Width = 489
                            $notificationGroupBox.Size = $System_Drawing_Size
                            $notificationGroupBox.TabIndex = 8
                            $notificationGroupBox.TabStop = $False
                            $notificationGroupBox.Text = "Notification Email"

                            $ErrorForm.Controls.Add($notificationGroupBox)
                            $emailToTextBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 61
                            $System_Drawing_Point.Y = 20
                            $emailToTextBox.Location = $System_Drawing_Point
                            $emailToTextBox.Name = "emailToTextBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 411
                            $emailToTextBox.Size = $System_Drawing_Size
                            $emailToTextBox.TabIndex = 3

                            $notificationGroupBox.Controls.Add($emailToTextBox)

                            $emailToLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 7
                            $System_Drawing_Point.Y = 22
                            $emailToLabel.Location = $System_Drawing_Point
                            $emailToLabel.Name = "emailToLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 19
                            $System_Drawing_Size.Width = 48
                            $emailToLabel.Size = $System_Drawing_Size
                            $emailToLabel.TabIndex = 0
                            $emailToLabel.Text = "To: "

                            $notificationGroupBox.Controls.Add($emailToLabel)


                            $errorRichTextBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 37
                            $errorRichTextBox.Location = $System_Drawing_Point
                            $errorRichTextBox.Name = "errorRichTextBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 460
                            $System_Drawing_Size.Width = 658
                            $errorRichTextBox.Size = $System_Drawing_Size
                            $errorRichTextBox.TabIndex = 5
                            $errorRichTextBox.Text = ""

                            $ErrorForm.Controls.Add($errorRichTextBox)

                            #endregion Generated Form Code

                            #$MainMenu.Topmost = $False
                            $ErrorForm.Topmost = $True
                            #Save the initial state of the form
                            $InitialFormWindowState = $ErrorForm.WindowState
                            #Init the OnLoad event to correct the initial state of the form
                            $ErrorForm.add_Load($OnLoadForm_StateCorrection)
                            #Show the Form
                            $ErrorForm.ShowDialog()| Out-Null

                            } #End Function
                            #endregion

                            #region ACL Functions
                            # Get-ACL function
                            function getACL($strFolderPath) {
                                try {
                                    $oACL = start-job -scriptblock {param($strFolderPath) `
                                            write-output (Get-ACL $strFolderPath)} -ArgumentList $strFolderPath,`
                                            ([Environment]::CurrentDirectory=$Env:windir) -Credential $global:serviceCredentials `
                                            | Wait-Job | Receive-Job
                                #	Write-Host $oACL
                                    if (!($oACL)) {
                                        postLog2 "getACL : Unable to retrieve ACL for $strFolderPath" "WARNING"
                                    }
                                    return $oACL
                                } catch { postLog2 "$ERROR" "ERROR" "getACL" }
                            }

                            function SetAclRights ($objNewAcl, [string]$strFolderPath) {
                                [string]$strRights = $objNewAcl.FileSystemRights
                                [string]$strGroup = $objNewAcl.IdentityReference
                                [string]$strInheritanceFlag = $objNewAcl.InheritanceFlags
                                [string]$strPropagationFlag = $objNewAcl.PropagationFlags
                                postLog2 "strFolderPath = $strFolderPath" "DEBUG" "SetAclRights"
                                postLog2 "strRights = $strRights" "DEBUG" "SetAclRights"
                                postLog2 "strGroup = $strGroup" "DEBUG" "SetAclRights"
                                postLog2 "strInheritenceFlag = $strInheritanceFlag" "DEBUG" "SetAclRights"
                                postLog2 "strPropagationFlag = $strPropagationFlag" "DEBUG" "SetAclRights"

                                do {
                                    Start-Sleep 1
                                    postLog "Waiting for ACL $strFolderPath..." "INFO" "SetAclRights"
                                } while (!(getACL $strFolderPath))
                                
                                $sbSetRights = {
                                    param($strRights,$strGroup,$strFolderPath,$strInheritanceFlag,$strPropagationFlag) `
                                        $objRights = [System.Security.AccessControl.FileSystemRights]$strRights
                                        $objInheritanceFlag = [System.Security.AccessControl.InheritanceFlags]$strInheritanceFlag 
                                        $objPropagationFlag = [System.Security.AccessControl.PropagationFlags]$strPropagationFlag
                                        $objType = [System.Security.AccessControl.AccessControlType]::Allow 
                                        $objGroup = New-Object System.Security.Principal.NTAccount($strGroup)
                                        $objACE = New-Object System.Security.AccessControl.FileSystemAccessRule(
                                                $objGroup, $objRights, $objInheritanceFlag, $objPropagationFlag, $objType)		
                                        $objACL = Get-Acl $strFolderPath
                                        $objACL.AddAccessRule($objACE)
                                        Set-ACL $strFolderPath $objACL
                                }
                                
                                postLog2 "Setting ACL rights for $strGroup on $strFolderPath..." "INFO" "SetAclRights"
                                
                                try {
                                    Start-Job -ScriptBlock $sbSetRights `
                                        -ArgumentList $strRights,$strGroup,$strFolderPath,$strInheritanceFlag,$strPropagationFlag,`
                                        ([Environment]::CurrentDirectory=$Env:windir) -Credential $global:serviceCredentials `
                                        | Wait-Job | receive-job
                                } catch [System.Exception] {
                                    postLog2 "$Error" "ERROR" "SetAclRights"
                                }
                                do {
                                    postLog2 "Waiting for $strGroup to be added to $strFolderPath" "INFO" "SetAclRights"
                                    $objACL = getACL $strFolderPath
                                    $objACL.AccessToString
                                    Start-Sleep 1
                                } while (!($objACL.AccessToString).Contains($objGroup))
                                postLog2 "$strGroup added to $strFolderPath" "INFO" "SetAclRights"
                            }

                            function MatchAcl ($oOriginalAccessRules, $oDefaultAcl) {
                                try {
                                    foreach ($oOriginalAcl in $oOriginalAccessRules) {	
                                        if (($oOriginalAcl.IdentityReference -eq $oDefaultAcl.IdentityReference) -and
                                                ($oOriginalAcl.AccessControlType -eq $oDefaultAcl.AccessControlType) -and 
                                                ($oOriginalAcl.FileSystemRights -eq $oDefaultAcl.FileSystemRights)) {
                                            return $True
                                        }
                                    }
                                } catch [System.Exception] {
                                    postLog2 "$Error" "ERROR" "MatchAcl"
                                }
                                return $False
                            }

                            function CheckAclExists ($oOriginalAccessRules, $oDefaultAcl) {
                                try {
                                    foreach ($oOriginalAcl in $oOriginalAccessRules) {		
                                        if ($oOriginalAcl.IdentityReference -eq $oDefaultAcl.IdentityReference) {
                                            return $True
                                        }
                                    }
                                } catch [System.Exception] {
                                    postLog2 "$Error" "ERROR" "MatchAcl"
                                }
                                return $False
                            }

                            #endregion 

                            #region Check Permissions

                            function LogAdditionalPermissions($objCorrectACL, $sFolderPath, $strState, $ShareOfficeAbbr) {
                                [string]$strIdentityReference = $objCorrectACL.IdentityReference
                                [string]$strAccessControlType = $objCorrectACL.AccessControlType
                                [string]$strFileSystemRights = $objCorrectACL.FileSystemRights

                                if ($global:sErrorBodyText -eq "") {
                                    $global:sErrorBodyText = $csAdditionalPermissionsDefaultText
                                }
                                $arrOfficePermissionExclusion | % {
                                    if ($_.Equals($ShareOfficeAbbr)) {
                                        # Create body text file			 
                                        $strErrorMessage = "$strIdentityReference on folder $sFolderPath with security rights $strFileSystemRights $strState"
                                        $global:sErrorBodyText = $global:sErrorBodyText + "`r`n`r`n" + $strErrorMessage
                                        postLog2 "$strErrorMessage" "WARNING" "LogAdditionalPermissions"
                                    } 
                                }	
                            }

                            function CheckPermissions($arrCheckRights, $strCheckFolderPath, $ShareOfficeAbbr, $bMatchExact=$True, $bVerify=$False) {
                                $bMatchAll = $True
                                try {
                                    $objCheckACL = getACL $strCheckFolderPath		
                                    $oAccessRules = $objCheckACL.GetAccessRules($True,$True,[System.Security.Principal.NTAccount])

                                    foreach ($oCheckRight in $arrCheckRights) {	
                                        if ($bMatchExact -eq $False) {
                                            if (MatchAcl $oAccessRules $oCheckRight) {
                                                postLog2 "$($oCheckRight.IdentityReference) matched!" "INFO" "checkPermissions"
                                            } else {
                                                if ($bVerify -eq $True) {
                                                    LogAdditionalPermissions $oCheckRight "$strCheckFolderPath" `
                                                        "-- $($oCheckRight.IdentityReference) is missing from $strCheckFolderPath!" `
                                                        "$ShareOfficeAbbr"
                                                }
                                                $bMatchAll = $False
                                            }
                                        } else {
                                            if (CheckAclExists $oAccessRules $oCheckRight) {
                                                postLog2 "$($oCheckRight.IdentityReference) matched!" "INFO" "checkPermissions"
                                            } else {
                                                if ($bVerify -eq $True) {
                                                    LogAdditionalPermissions $oCheckRight "$strCheckFolderPath" `
                                                        "-- $($oCheckRight.IdentityReference) is incorrectly applied to $strCheckFolderPath!"
                                                }
                                                $bMatchAll = $False
                                            }
                                        }
                                    }
                                } catch [System.Exception] {
                                    postLog2 "$Error" "ERROR" "CheckPermissions"
                                }
                                return $bMatchAll
                            }

                            #endregion

                            #region Get Default Permissions

                            function getDefaultPermissions ($oAccess) {
                            # Check Language
                                $strLanguage = "EN"
                                foreach ($oAclName in $oAccess) {
                                    if ($oAclName.IdentityReference -eq "AUTORITE NT\SYSTEM") { $strLanguage = "FR" }
                                    if ($oAclName.IdentityReference -eq "NT-AUTORIT�T\SYSTEM") { $strLanguage = "GR" }
                                }
                                postLog2 "Language is $strLanguage" "INFO" "checkFolderPermissions"
                                switch ($strLanguage) {
                                    "EN" { 
                                        $global:BUILTIN = "BUILTIN" 
                                        $global:NTAUTHORITY = "NT AUTHORITY"
                                        $global:CREATOROWNER = "CREATOR OWNER"
                                    }
                                    "FR" {
                                        $global:BUILTIN = "BUILTIN"
                                        $global:NTAUTHORITY = "AUTORITE NT"
                                        $global:CREATOROWNER = "CREATEUR PROPRIETAIRE"
                                        }
                                    "GR" {
                                        $global:BUILTIN = "VORDEFINIERT"
                                        $global:NTAUTHORITY = "NT-AUTORIT�T"
                                        $global:CREATOROWNER = "ERSTELLER-BESITZER"
                                        }
                                    }
                            #	Write-Host $BUILTIN $NTAUTHORITY
                                
                            }
                            #endregion

                            #region Check for extra permissions on folder
                            function checkExtraPermissions ($strShareGroup, $strExtraFolderPath) {
                                postStatus "Checking for additional permissions on folders..." "INFO"
                                
                                try {
                                    $objExtraACL = getACL $strExtraFolderPath		
                                    $oAccessRules = $objExtraACL.GetAccessRules($True,$True,[System.Security.Principal.NTAccount])
                                    $aDefaultPermissions = "TEST\SupportServices","TEST\$strShareGroup","$global:BUILTIN\Administrators","$global:NTAUTHORITY\SYSTEM","$global:CREATOROWNER","TEST\PST"

                                    $oAccessRules | % {
                                        if ($aDefaultPermissions -notcontains [string]$_.IdentityReference) 
                                        { 
                                            LogAdditionalPermissions $_ "$strExtraFolderPath" "-- should be removed from folder security!"
                                        }
                                    }
                                } catch [System.Exception] {
                                    postLog2 "$Error" "ERROR" "checkExtraPermissions"
                                }
                            }
                            #endregion 

                            #region Save/Restore Data in Form
                            # Save Object and Form Data
                            function saveDataToCache ($strSaveData) {
                                Export-CliXML -InputObject $UserListBox.Items -Path "$sTempFolder\users.xml" -Force
                                Export-CliXML -InputObject $GroupListBox.Items -Path "$sTempFolder\groups.xml" -Force
                                Clear-Content -Path "$sTempFolder\dfs.dat"
                                Add-Content -Path "$sTempFolder\dfs.dat" -Value $strSaveData -Force
                                postLog "saveData : $strSaveData" "INFO"
                            }

                            # Import Object and Form Data
                            function reloadCachedData {
                                postStatus "Restoring data..." "INFO"
                                $UserListBox.Items.Clear()
                                $GroupListBox.Items.Clear()
                                
                                if (Test-Path "$sTempFolder\users.xml") {
                                    $UserListBoxItems = Import-Clixml -Path "$sTempFolder\users.xml"
                                    foreach ($listItem in $UserListBoxItems) {
                                        $UserListBox.Items.Add($listItem)
                                    }
                                } elseif (Test-Path "$sTempFolder\dfs.xml") {
                                    $UserListBoxItems = Import-Clixml -Path "$sTempFolder\dfs.xml"
                                    foreach ($listItem in $UserListBoxItems) {
                                        $UserListBox.Items.Add($listItem)
                                    }
                                } 
                                if (Test-Path "$sTempFolder\groups.xml") {
                                    $GroupListBoxItems = Import-Clixml -Path "$sTempFolder\groups.xml"
                                    foreach ($listItem in $GroupListBoxItems) {
                                        $GroupListBox.Items.Add($listItem)
                                    }
                                } 
                                if (Test-Path "$sTempFolder\dfs.dat") {
                                    $strSaveData = Get-Content -Path "$sTempFolder\dfs.dat"
                                    if ($strSaveData) {
                                        $arrSaveData = $strSaveData.Split(",")
                                        if ($arrSaveData[0]) {$ClientNameTextBox.Text = $arrSaveData[0]}
                                        if ($arrSaveData[1]) {$ClientNumberTextBox.Text = $arrSaveData[1]}
                                        if ($arrSaveData[2]) {$MatterNumberTextBox.Text = $arrSaveData[2]}
                                        if ($arrSaveData[3]) {$MatterNameTextBox.Text = $arrSaveData[3]}
                                        if ($arrSaveData[4]) {$ShareOfficeComboBox.SelectedItem = $arrSaveData[4]}
                                        if ($arrSaveData[5]) {$ShareDataComboBox.Text = $arrSaveData[5]}
                                        if ($arrSaveData[6]) {$ShareImagesComboBox.Text = $arrSaveData[6]}			
                                        
                                        postStatus "Restored saved data" "INFO"
                                    } else {
                                        postStatus "No Saved Data to retrieve!" "INFO"
                                    }
                                } else {
                                    postStatus "No Saved Data to retrieve!" "INFO"
                                }
                            }
                            #endregion

                            #region Check Information on Form
                            function checkaccuracy ($arrUsers, $arrGroups) {
                            ########################################################################
                            # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.9.0
                            # Generated On: 4/6/2011 1:36 PM
                            # Generated By: dsuyemot
                            ########################################################################

                            #region Import the Assemblies
                            [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
                            [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
                            #endregion

                            #region Generated Form Objects
                            $CheckAccuracy = New-Object System.Windows.Forms.Form
                            $GroupLabel = New-Object System.Windows.Forms.Label
                            $GroupListBox = New-Object System.Windows.Forms.ListBox
                            $label9 = New-Object System.Windows.Forms.Label
                            $ShareOffice = New-Object System.Windows.Forms.TextBox
                            $MatterName = New-Object System.Windows.Forms.TextBox
                            $label5 = New-Object System.Windows.Forms.Label
                            $ServerName = New-Object System.Windows.Forms.TextBox
                            $label8 = New-Object System.Windows.Forms.Label
                            $ImagesShareName = New-Object System.Windows.Forms.TextBox
                            $label7 = New-Object System.Windows.Forms.Label
                            $DataShareName = New-Object System.Windows.Forms.TextBox
                            $label6 = New-Object System.Windows.Forms.Label
                            $MatterNumber = New-Object System.Windows.Forms.TextBox
                            $ClientNumber = New-Object System.Windows.Forms.TextBox
                            $ClientName = New-Object System.Windows.Forms.TextBox
                            $UserListBox = New-Object System.Windows.Forms.ListBox
                            $label4 = New-Object System.Windows.Forms.Label
                            $label3 = New-Object System.Windows.Forms.Label
                            $label2 = New-Object System.Windows.Forms.Label
                            $UserLabel = New-Object System.Windows.Forms.Label
                            $noButton = New-Object System.Windows.Forms.Button
                            $yesButton = New-Object System.Windows.Forms.Button
                            $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
                            #endregion Generated Form Objects

                            #----------------------------------------------
                            #Generated Event Script Blocks
                            #----------------------------------------------
                            #Provide Custom Code for events specified in PrimalForms.
                            $handler_MessageForm1_Load= 
                            {
                                foreach($userName in $arrUsers) {
                                    $UserListBox.Items.add($userName)
                                }
                                foreach($groupName in $arrGroups) {
                                    $GroupListBox.Items.Add($groupName)
                                }
                                $ClientName.Text = $ClientNameTextBox.Text
                                $ClientNumber.Text = $ClientNumberTextBox.Text
                                $MatterNumber.Text = $MatterNumberTextBox.Text
                                $DataShareName.Text = $ShareDataComboBox.Text
                                $ImagesShareName.Text = $ShareImagesComboBox.Text
                                $MatterName.Text = $MatterNameTextBox.Text
                                $ShareOffice.Text = $ShareOfficeComboBox.Text
                            }

                            $yesButton_OnClick= 
                            {
                                $CheckAccuracy.close()
                                if($VerifyClientFolder) {
                                    $VerifyClientFolder.Close()
                                }
                                $ClientNameTextBox.enabled=$False
                                $ClientNumberTextBox.enabled=$False
                                $MatterNameTextBox.enabled=$False
                                $MatterNumberTextBox.enabled=$False
                                $ShareOfficeComboBox.enabled=$False
                                $ShareDataComboBox.enabled=$False
                                $ShareImagesComboBox.enabled=$False
                                $UserAddButton.enabled=$False
                                $cancelButton.enabled=$False
                            }

                            $noButton_OnClick= 
                            {
                                postStatus "Cancelled! Press OK to start" "INFO"
                                
                                if ($VerifyClientFolder) {
                                    $changeButton.enabled = $True
                                    $stopButton.enabled = $True
                                    $continueButton.enabled = $True
                                } else {
                                    $OKbuttonMain.enabled=$True
                                }
                                $CheckAccuracy.close()
                            }

                            $OnLoadForm_StateCorrection=
                            {#Correct the initial state of the form to prevent the .Net maximized form issue
                                $CheckAccuracy.WindowState = $InitialFormWindowState
                            }

                            #----------------------------------------------
                            #region Generated Form Code
                            $CheckAccuracy.AutoSize = $True
                            $CheckAccuracy.AutoSizeMode = 0
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 380
                            $System_Drawing_Size.Width = 292
                            $CheckAccuracy.ClientSize = $System_Drawing_Size
                            $CheckAccuracy.DataBindings.DefaultDataSourceUpdateMode = 0
                            $CheckAccuracy.Name = "CheckAccuracy"
                            $CheckAccuracy.Text = "Is This Correct?"
                            $CheckAccuracy.add_Load($handler_MessageForm1_Load)

                            $GroupLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 13
                            $System_Drawing_Point.Y = 73
                            $GroupLabel.Location = $System_Drawing_Point
                            $GroupLabel.Name = "GroupLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 100
                            $GroupLabel.Size = $System_Drawing_Size
                            $GroupLabel.TabIndex = 25
                            $GroupLabel.Text = "Group(s):"

                            $CheckAccuracy.Controls.Add($GroupLabel)

                            $GroupListBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $GroupListBox.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 134
                            $System_Drawing_Point.Y = 73
                            $GroupListBox.Location = $System_Drawing_Point
                            $GroupListBox.Name = "GroupListBox"
                            $GroupListBox.ScrollATESTaysVisible = $True
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 56
                            $System_Drawing_Size.Width = 131
                            $GroupListBox.Size = $System_Drawing_Size
                            $GroupListBox.TabIndex = 24

                            $CheckAccuracy.Controls.Add($GroupListBox)

                            $label9.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 240
                            $label9.Location = $System_Drawing_Point
                            $label9.Name = "label9"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 100
                            $label9.Size = $System_Drawing_Size
                            $label9.TabIndex = 23
                            $label9.Text = "Share Office"

                            $CheckAccuracy.Controls.Add($label9)

                            $ShareOffice.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 133
                            $System_Drawing_Point.Y = 237
                            $ShareOffice.Location = $System_Drawing_Point
                            $ShareOffice.Name = "ShareOffice"
                            $ShareOffice.ReadOnly = $True
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 131
                            $ShareOffice.Size = $System_Drawing_Size
                            $ShareOffice.TabIndex = 22

                            $CheckAccuracy.Controls.Add($ShareOffice)

                            $MatterName.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 133
                            $System_Drawing_Point.Y = 214
                            $MatterName.Location = $System_Drawing_Point
                            $MatterName.Name = "MatterName"
                            $MatterName.ReadOnly = $True
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 131
                            $MatterName.Size = $System_Drawing_Size
                            $MatterName.TabIndex = 21

                            $CheckAccuracy.Controls.Add($MatterName)

                            $label5.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 217
                            $label5.Location = $System_Drawing_Point
                            $label5.Name = "label5"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 100
                            $label5.Size = $System_Drawing_Size
                            $label5.TabIndex = 20
                            $label5.Text = "Matter Name:"

                            $CheckAccuracy.Controls.Add($label5)

                            $ServerName.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 133
                            $System_Drawing_Point.Y = 306
                            $ServerName.Location = $System_Drawing_Point
                            $ServerName.Name = "ServerName"
                            $ServerName.ReadOnly = $True
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 131
                            $ServerName.Size = $System_Drawing_Size
                            $ServerName.TabIndex = 19

                            $CheckAccuracy.Controls.Add($ServerName)

                            $label8.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 309
                            $label8.Location = $System_Drawing_Point
                            $label8.Name = "label8"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 100
                            $label8.Size = $System_Drawing_Size
                            $label8.TabIndex = 18
                            $label8.Text = "Server Name:"

                            $CheckAccuracy.Controls.Add($label8)

                            $ImagesShareName.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 133
                            $System_Drawing_Point.Y = 283
                            $ImagesShareName.Location = $System_Drawing_Point
                            $ImagesShareName.Name = "ImagesShareName"
                            $ImagesShareName.ReadOnly = $True
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 131
                            $ImagesShareName.Size = $System_Drawing_Size
                            $ImagesShareName.TabIndex = 17

                            $CheckAccuracy.Controls.Add($ImagesShareName)

                            $label7.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 286
                            $label7.Location = $System_Drawing_Point
                            $label7.Name = "label7"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 115
                            $label7.Size = $System_Drawing_Size
                            $label7.TabIndex = 16
                            $label7.Text = "Images Share Name:"

                            $CheckAccuracy.Controls.Add($label7)

                            $DataShareName.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 133
                            $System_Drawing_Point.Y = 260
                            $DataShareName.Location = $System_Drawing_Point
                            $DataShareName.Name = "DataShareName"
                            $DataShareName.ReadOnly = $True
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 131
                            $DataShareName.Size = $System_Drawing_Size
                            $DataShareName.TabIndex = 15

                            $CheckAccuracy.Controls.Add($DataShareName)

                            $label6.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 263
                            $label6.Location = $System_Drawing_Point
                            $label6.Name = "label6"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 100
                            $label6.Size = $System_Drawing_Size
                            $label6.TabIndex = 14
                            $label6.Text = "Data Share Name:"

                            $CheckAccuracy.Controls.Add($label6)

                            $MatterNumber.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 133
                            $System_Drawing_Point.Y = 191
                            $MatterNumber.Location = $System_Drawing_Point
                            $MatterNumber.Name = "MatterNumber"
                            $MatterNumber.ReadOnly = $True
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 131
                            $MatterNumber.Size = $System_Drawing_Size
                            $MatterNumber.TabIndex = 12

                            $CheckAccuracy.Controls.Add($MatterNumber)

                            $ClientNumber.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 133
                            $System_Drawing_Point.Y = 168
                            $ClientNumber.Location = $System_Drawing_Point
                            $ClientNumber.Name = "ClientNumber"
                            $ClientNumber.ReadOnly = $True
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 131
                            $ClientNumber.Size = $System_Drawing_Size
                            $ClientNumber.TabIndex = 11

                            $CheckAccuracy.Controls.Add($ClientNumber)

                            $ClientName.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 133
                            $System_Drawing_Point.Y = 145
                            $ClientName.Location = $System_Drawing_Point
                            $ClientName.Name = "ClientName"
                            $ClientName.ReadOnly = $True
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 131
                            $ClientName.Size = $System_Drawing_Size
                            $ClientName.TabIndex = 10

                            $CheckAccuracy.Controls.Add($ClientName)

                            $UserListBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $UserListBox.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 134
                            $System_Drawing_Point.Y = 11
                            $UserListBox.Location = $System_Drawing_Point
                            $UserListBox.Name = "UserListBox"
                            $UserListBox.ScrollATESTaysVisible = $True
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 56
                            $System_Drawing_Size.Width = 131
                            $UserListBox.Size = $System_Drawing_Size
                            $UserListBox.TabIndex = 9

                            $CheckAccuracy.Controls.Add($UserListBox)

                            $label4.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 194
                            $label4.Location = $System_Drawing_Point
                            $label4.Name = "label4"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 100
                            $label4.Size = $System_Drawing_Size
                            $label4.TabIndex = 6
                            $label4.Text = "Matter Number:"

                            $CheckAccuracy.Controls.Add($label4)

                            $label3.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 171
                            $label3.Location = $System_Drawing_Point
                            $label3.Name = "label3"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 100
                            $label3.Size = $System_Drawing_Size
                            $label3.TabIndex = 5
                            $label3.Text = "Client Number:"

                            $CheckAccuracy.Controls.Add($label3)

                            $label2.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 148
                            $label2.Location = $System_Drawing_Point
                            $label2.Name = "label2"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 100
                            $label2.Size = $System_Drawing_Size
                            $label2.TabIndex = 4
                            $label2.Text = "Client Name:"

                            $CheckAccuracy.Controls.Add($label2)

                            $UserLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 13
                            $System_Drawing_Point.Y = 13
                            $UserLabel.Location = $System_Drawing_Point
                            $UserLabel.Name = "UserLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 100
                            $UserLabel.Size = $System_Drawing_Size
                            $UserLabel.TabIndex = 3
                            $UserLabel.Text = "User(s):"

                            $CheckAccuracy.Controls.Add($UserLabel)


                            $noButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 189
                            $System_Drawing_Point.Y = 341
                            $noButton.Location = $System_Drawing_Point
                            $noButton.Name = "noButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 75
                            $noButton.Size = $System_Drawing_Size
                            $noButton.TabIndex = 2
                            $noButton.Text = "No"
                            $noButton.UseVisualStyleBackColor = $True
                            $noButton.add_Click($noButton_OnClick)

                            $CheckAccuracy.Controls.Add($noButton)


                            $yesButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 108
                            $System_Drawing_Point.Y = 341
                            $yesButton.Location = $System_Drawing_Point
                            $yesButton.Name = "yesButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 75
                            $yesButton.Size = $System_Drawing_Size
                            $yesButton.TabIndex = 1
                            $yesButton.Text = "Yes"
                            $yesButton.UseVisualStyleBackColor = $True
                            $yesButton.add_Click($yesButton_OnClick)

                            $CheckAccuracy.Controls.Add($yesButton)

                            #endregion Generated Form Code
                            $CheckAccuracy.Topmost = $True
                            #Save the initial state of the form
                            $InitialFormWindowState = $CheckAccuracy.WindowState
                            #Init the OnLoad event to correct the initial state of the form
                            $CheckAccuracy.add_Load($OnLoadForm_StateCorrection)
                            #Show the Form
                            $CheckAccuracy.ShowDialog()| Out-Null

                            } #End Function
                            #endregion

                            #region Search for Username
                            function searchUsername ($strCriteria1,$strCriteria2) {
                                if ($strCriteria2 -and $strCriteria1) {
                                    $sSearchFilter = "Name -like `"*$strCriteria1*`" -and Name -like `"*$strCriteria2*`""
                                } elseif ($strCriteria2) {
                                    $sSearchFilter = "Name -like `"*$strCriteria2*`""
                                } elseif ($strCriteria1) {
                                    $sSearchFilter = "Name -like `"*$strCriteria1*`""
                                } else {
                                    Write-Host "Please enter search criteria!"
                                    return
                                }

                                Get-ADUser -Filter $sSearchFilter -SearchBase "DC=test,DC=com"
                            }
                            #endregion

                            #region Create Security Groups and add Users	
                            function createSecurityGroups ($arrDisplayNames, $arrSecurityGroups) {
                                $arrParm = "User Names=$arrDisplayNames", "Client Name=$ClientName","Client Number=$ClientNumber", 
                                    "Matter Number=$MatterNumber","Share Office Abbreviation=$ShareOfficeAbbr",
                                    "Data Share Name=$ShareNameData", "Images Share Name=$ShareNameImages", 
                                    "Group OU=$GroupOU", "Security Groups=$arrSecurityGroups"

                                $arrParm | % { postLog "createSecurityGroups : $_" "INFO" }

                            # Create Security Groups
                                postStatus "Creating Security Groups" "INFO"
                                postStatus "createSecurityGroups : $strShareMatterGroup" "INFO"
                                try { $objShareMatterGroup = Get-ADGroup $strShareMatterGroup -Credential $global:serviceCredentials } catch {}
                                postStatus "createSecurityGroups : $objShareMatterGroup" "INFO"
                            # Create Share Security Groups
                                if (!($objShareMatterGroup)) {
                            # Create Matter Group
                                    try {
                                        New-ADGroup -Name $strShareMatterGroup -SamAccountName $strShareMatterGroup `
                                            -GroupScope Global -GroupCategory Security -Path $strShareParentContainer -Credential $global:serviceCredentials
                                        postStatus "Creating $strShareMatterGroup..." "INFO"
                                        do { 
                                            try { 
                                                $objShareMatterGroup = Get-ADGroup $strShareMatterGroup -Credential $global:serviceCredentials 
                                            } catch {} 
                                        } while(!($objShareMatterGroup))
                                        postLog "createSecurityGroups : Created $strShareMatterGroup in $strShareParentContainer" "INFO"
                                    } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }
                                } else {
                                    postLog "createSecurityGroups : $strShareMatterGroup already exists in $strShareParentContainer!" "INFO"
                                }
                                try { $objShareClientGroup = Get-ADGroup $strShareClientGroup -Credential $global:serviceCredentials } catch {}
                                if (!($objShareClientGroup)) {
                            # Create Client Security Group
                                    try {
                                        New-ADGroup -Name $strShareClientGroup -SamAccountName $strShareClientGroup `
                                            -GroupScope Global -GroupCategory Security -Path $strShareParentContainer `
                                            -Credential $global:serviceCredentials
                                        postStatus "Creating $strShareClientGroup..." "INFO"
                                        do { 
                                            try { 
                                                $objShareClientGroup = Get-ADGroup $strShareClientGroup -Credential $global:serviceCredentials 
                                            } catch {} 
                                        } while(!($objShareClientGroup))
                                        postLog "createSecurityGroups : Created $strShareClientGroup in $strShareParentContainer" "INFO"
                                    } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }	
                                } else {
                                    postLog "createSecurityGroups : $strShareClientGroup already exists in $strShareParentContainer !" "INFO"
                                }
                                
                            # Add Matter Group to Client Group
                                try { 
                                    $oFoundShareMatterGroupOf = Get-ADGroupMember $strShareClientGroup -Credential $global:serviceCredentials | ? { $_.Name -eq $strShareMatterGroup.Name }
                                } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }

                                if ($oFoundShareMatterGroupOf) {
                                    postLog "createSecurityGroups : $strShareMatterGroup already exists in $strShareClientGroup!" "INFO"
                                } else {
                                    try {
                                        Add-ADGroupMember $objShareClientGroup -Members $objShareMatterGroup -Credential $global:serviceCredentials
                                        postLog "createSecurityGroups : Added $strShareMatterGroup to $strShareClientGroup" "INFO"
                                    } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }
                                }

                            # Add PST to Matter Group
                                if ($global:bTESTPstCheckBoxState)
                                {
                                    try {
                                        $oTESTPst = Get-ADGroup "PST" -Credential $global:serviceCredentials 
                                    } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }

                                    try {
                                        $oShareMatterGroup = Get-ADGroup $strShareMatterGroup -Credential $global:serviceCredentials 
                                    } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }

                                    try {
                                        $oFoundTESTPst = Get-ADGroupMember $strShareMatterGroup -Recursive -Credential $global:serviceCredentials | ? { $_.Name -eq $oTESTPst.Name }
                                    } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }

                                    if ($oFoundTESTPst) {
                                        postLog "createSecurityGroups : PST already exists in $strShareMatterGroup!" "INFO"
                                    } else {
                                        try {
                                            Add-ADGroupMember $oShareMatterGroup -Members $oTESTPst -Credential $global:serviceCredentials
                                            postLog "createSecurityGroups : Added PST to $strShareMatterGroup" "INFO"
                                        } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }
                                    }
                                }	

                            # Create User Security Groups (if in different office)
                                foreach($sDisplayName in $arrDisplayNames) {
                                
                            # Get User Office
                                    $UserName = (Get-ADUser -Filter "Name -eq `'$sDisplayName`'").SamAccountName
                                    $strUserOfficeAbbr = getUserOffice $UserName
                                    $strUserMatterGroup = "$strUserOfficeAbbr $ClientNumber`_$MatterNumber"
                                    postLog2 "strUserMatterGroup = $strUserMatterGroup" "createSecurityGroups"		
                                    
                            # Get Office OU
                                    $GroupOU = GetOfficeGroupOU $strUserOfficeAbbr
                                    $strUserOfficeOU = $strUserOfficeAbbr

                                    $strUserParentContainer = "ou=$GroupOU,ou=$strUserOfficeOU,dc=test,dc=com"
                                    $objUserMatterGroup = $null
                                    try { $objUserMatterGroup = Get-ADGroup $strUserMatterGroup -Credential $global:serviceCredentials } catch {}
                                    
                            # Create User Matter Group if necessary
                                    if (!($objUserMatterGroup)) {
                                        try {
                                            New-ADGroup -Name $strUserMatterGroup -SamAccountName $strUserMatterGroup `
                                                    -GroupScope Global -GroupCategory Security -Path $strUserParentContainer `
                                                    -Credential $global:serviceCredentials
                                        } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }
                                        do { 
                                            try { $objUserMatterGroup = Get-ADGroup $strUserMatterGroup -Credential $global:serviceCredentials } catch {} 
                                        } while(!($objUserMatterGroup))
                                        postLog2 "Created $strUserMatterGroup in $strUserParentContainer" "INFO" "createSecurityGroups"
                                    } else {
                                        postLog2 "$strUserMatterGroup already exists!" "INFO" "createSecurityGroups"
                                    }
                                        
                            # Add User Matter Security Group to Share Matter Security Group if necessary
                                    if ($objUserMatterGroup -notlike $objShareMatterGroup) {
                                        try {
                                            $objFoundUserMatterGroupOf = Get-ADGroupMember $objShareMatterGroup -Credential $global:serviceCredentials | ? { $_.Name -eq $objUserMatterGroup.Name }
                                        } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }

                                        if ($objFoundUserMatterGroupOf) {
                                            postLog2 "$strUserMatterGroup already exists in $strShareMatterGroup !" "INFO" "createSecurityGroups"
                                        } else {
                                            Add-ADGroupMember $objShareMatterGroup -Members $objUserMatterGroup -Credential $global:serviceCredentials 
                                            postLog2 "Added $strUserMatterGroup to $strShareMatterGroup" "INFO" "createSecurityGroups"
                                        }
                                    }
                                    
                            # Add User to Matter Group
                                    $objUsername = Get-ADUser $UserName -Credential $global:serviceCredentials
                                    try {
                                        $oFoundUserGroupOf = Get-ADGroupMember $strUserMatterGroup -Recursive -Credential $global:serviceCredentials | ? { $_.Name -eq $objUsername.Name }
                                    } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }
                                    if ($oFoundUserGroupOf) {
                                        postLog2 "$UserName is already added to $strUserMatterGroup" "INFO" "createSecurityGroups"
                                    } else {
                                        try {
                                            Add-ADGroupMember $objUserMatterGroup -Members $objUsername -Credential $global:serviceCredentials 
                                            postLog2 "Added $UserName to $strUserMatterGroup" "INFO" "createSecurityGroups"
                                        } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }
                                    }
                                }

                            # Add Security Groups into Matter Group
                                foreach ($sSecurityGroup in $arrSecurityGroups) {
                                    try {
                                        $objFoundSecurityGroup = Get-AdGroupMember $strUserMatterGroup -Credential $global:serviceCredentials | ? { $_.Name -eq $sSecurityGroup }
                                    } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }
                                    if ($objFoundSecurityGroup) {
                                        postLog2 "$sSecurityGroup is already added to $strUserMatterGroup" "INFO" "createSecurityGroups"
                                    } else {
                                        try { 
                                            $objSecurityGroup = Get-ADGroup $sSecurityGroup -Credential $global:serviceCredentials
                                            Add-ADGroupMember $objShareMatterGroup -Members $objSecurityGroup -Credential $global:serviceCredentials 
                                            postLog2 "Added $sSecurityGroup to $($objShareMatterGroup.Name)" "INFO" "createSecurityGroups"
                                        } catch [System.Exception] { postLog2 "$Error" "ERROR" "createSecurityGroups" }
                                    }
                                }
                                postStatus "Security Groups complete" "INFO"
                            }
                            #endregion

                            #region Create Folder
                            function createFolder($strSharePath, $strFolderPath, $strFolderType, $strShareGroup, $ShareOfficeAbbr) {
                                try {
                                    $objACL = getACL $strSharePath
                                        
                                    try {
                                        $oAccessRules = $objACL.GetAccessRules($True,$True,[System.Security.Principal.NTAccount])
                                    } catch { postLog "createFolder : Unable to get access rules for $strSharePath"; exit }
                                                
                                    getDefaultPermissions $oAccessRules

                                    switch ($strFolderType) {
                                            "DataClient" { $objGroupAccess = $objGroupClientAccess; $objSupportServicesAccess = $objSupportServicesClientAccess }
                                            "DataMatter" { $objGroupAccess = $objGroupDataMatterAccess; $objSupportServicesAccess = $objSupportServicesDataMatterAccess }
                                            "ImagesClient" { $objGroupAccess = $objGroupClientAccess; $objSupportServicesAccess = $objSupportServicesClientAccess }
                                            "ImagesMatter" { $objGroupAccess = $objGroupImagesMatterAccess; $objSupportServicesAccess = $objSupportServicesImagesMatterAccess }
                                            default { }
                                        }
                                    
                                    $arrDefaultRights = $(@($objLocalAdministratorsAccess, $objSystemAccess))
                                    $arrGroupRights = @($objGroupAccess)
                                    $arrSupportServicesRights = @($objSupportServicesAccess)
                                    
                                    # Check if folder exists
                                    if(!(testPath $strFolderPath)) {
                                        # Create folder
                                        postStatus "Creating $strFolderPath folder..." "INFO"
                                        start-job -scriptblock {param($strFolderPath) New-Item $strFolderPath -type directory} `
                                                -argumentlist $strFolderPath,([Environment]::CurrentDirectory=$Env:windir) `
                                                -Credential $global:serviceCredentials | Wait-Job | Receive-Job
                                        do {
                                            postLog "createFolder : Verifying folder is created..." "INFO"
                                            $strNewFolderResult = testPath $strFolderPath
                                        } while (!$strNewFolderResult) 
                                        postLog "createFolder : Created $strFolderPath folder" "INFO"
                                        
                                        # Assign Rights			
                                        SetAclRights $objGroupAccess $strFolderPath			
                                        SetAclRights $objSupportServicesAccess $strFolderPath	
                                
                                    } else {
                                        postLog "createFolder : $strFolderPath folder already exists!" "INFO"
                                    }	
                                    
                                    # Check Default Security Rights
                                    checkPermissions $arrDefaultRights $strFolderPath $ShareOfficeAbbr $True $True
                                        
                                    # Check if Group Security is present on folder
                                    checkPermissions $arrGroupRights $strFolderPath $ShareOfficeAbbr $True $True
                                    
                                    # Check if SupportServices Group exists on folder
                                    checkPermissions $arrSupportServicesRights $strFolderPath $ShareOfficeAbbr $True $True
                                    
                                    # Check for Extra Groups/Users
                                    checkExtraPermissions $strShareGroup $strFolderPath
                                } catch [System.Exception] { 
                                    postStatus "ERROR! See log for details"
                                    postLog2 "$Error" "ERROR" "createFolder"
                                    }
                            }
                            #endregion

                            #region Assign Rights (NOT USED)
                            <#
                            function assignRights($strFolder,$strGroupName,$objCorrectAccess,$strRights,$strGroup,$strInheritFlag,$strPropagationFlag) {		
                                    # Check access on folder
                                    $objDataClientFolderPath = getACL $strFolder
                                    $oDataClientAccess = $objDataClientFolderPath.GetAccessRules($True,$True,`
                                            [System.Security.Principal.NTAccount])
                                    $boolFolder=$False
                                    foreach ($objAccess in $oDataClientAccess) {
                                        if (($objAccess.FileSystemRights -eq $objCorrectAccess.FileSystemRights) -and `
                                                ($objAccess.IdentityReference -eq $objCorrectAccess.IdentityReference) -and `
                                                ($objAccess.AccessControlType -eq $objCorrectAccess.AccessControlType)) {
                                            $boolFolder=$True
                                        }
                                    }
                                    # Assign permissions
                                    if ($boolFolder) {
                                        postLog "assignRights : $strGroupName already has rights to $strFolder" "INFO"
                                    } else {
                                        postLog "assignRights : Assigning Rights for $strGroupName to $strFolder..." "INFO"
                                        if (Get-QADGroup -Name "$strGroupName" -Credential $global:serviceCredentials) {
                                            SetRights $strRights $strGroup $strInheritFlag $strFolder $strPropagationFlag
                                        } else {
                                            postLog "assignRights : Could not find $strGroupName, please fix and rerun script!" "INFO"
                                        }			
                                    }
                            }
                            #>
                            #endregion

                            #region Create Data & Images Folders & Assign Default Permissions
                            function createDataImagesFolders(
                                [string]$sShareNameData,
                                [string]$sShareNameImages,
                                [string]$sClientName,
                                [string]$sClientNumber,
                                [string]$sMatterName,
                                [string]$sMatterNumber) {
                                
                                if ($sMatterName) { 
                                    $sMatterNumberName = $sMatterNumber + "`_" + $sMatterName
                                } else {
                                    $sMatterNumberName = $sMatterNumber
                                }
                                if ($sClientName) {
                                    $sClientNumberName = $sClientNumber + "`_" + $sClientName
                                    $strShareClientGroup = "$ShareOfficeAbbr $sClientNumber`_$sClientName"
                                } else {
                                    $sClientNumberName = $sClientNumber	
                                    $strShareClientGroup = "$ShareOfficeAbbr $sClientNumber"
                                }
                                $strShareMatterGroup = "$ShareOfficeAbbr $sClientNumber`_$sMatterNumber"
                                $boolErrors = $False
                                
                                # Check if Data field is selected
                                if (($sShareNameData) -and ($sShareNameData -ne "Select:")) {
                                    $strDataClientFolderPath = "$sShareNameData\$sClientNumberName" 
                                    $strDataMatterFolderPath = "$strDataClientFolderPath\$sMatterNumberName"		
                                    
                                    # Create Data Client Folder
                                    createFolder $sShareNameData $strDataClientFolderPath "DataClient" $strShareClientGroup $ShareOfficeAbbr
                                
                                    # Create Data Matter Folder
                                    createFolder $sShareNameData $strDataMatterFolderPath "DataMatter" $strShareMatterGroup $ShareOfficeAbbr
                                    
                                }

                                # Check if Images field is selected	
                                if (($sShareNameImages) -and ($sShareNameImages -ne "Select:")) {
                                    $strImagesClientFolderPath = "$sShareNameImages\$sClientNumberName" 
                                    $strImagesMatterFolderPath = "$strImagesClientFolderPath\$sMatterNumberName"
                                            
                                    # Create Images Client Folder
                                    createFolder $sShareNameImages $strImagesClientFolderPath "ImagesClient" $strShareClientGroup $ShareOfficeAbbr
                                
                                    # Create Images Matter Folder
                                    createFolder $sShareNameImages $strImagesMatterFolderPath "ImagesMatter" $strShareMatterGroup $ShareOfficeAbbr	
                                }
                            }
                            #endregion
                                
                            #region Create DFS Links
                            function createDFS(
                                [string]$sShareNameData,
                                [string]$sShareNameImages,
                                [string]$sClientName,
                                [string]$sClientNumber,
                                [string]$sMatterName,
                                [string]$sMatterNumber) {

                                postStatus "Creating DFS Links..." "INFO"
                                [array] $arrFolders=@("Data","Images")
                                if ($sMatterName -ne "") { 
                                    $sMatterNumberName = $sMatterNumber+'_'+$sMatterName 
                                } else {
                                    $sMatterNumberName = $sMatterNumber
                                }
                                if ($sClientName -ne "") { 
                                    $sClientFolderName = $sClientNumber+'_'+$sClientName 
                                } else {
                                    $sClientFolderName = $sClientNumber
                                } else {
                                    [string]$DfsShareOfficeAbbr = $ShareOfficeComboBox.Text
                                }

                                # Lookup DFS Namespace root for office
                                c:
                                $cmd = "dfsutil /displaydfspath"
                                $cmd2 = "\\test.com\clientdata\$DfsShareOfficeAbbr"
                                [String]$strDFSCmd = "${cmd}:$cmd2"
                                [String]$strDFSPathOutput = cmd /c $strDFSCmd

                                $strDFSNamespaceRoot = $strDFSPathOutput.Substring($strDFSPathOutput.LastIndexOf("<")+1,`
                                        $strDFSPathOutput.LastIndexOf(">")-$strDFSPathOutput.LastIndexOf("<")-1)
                                postLog "createDFS : DFS Namespace root = $strDFSNamespaceroot" "INFO"

                                $strTestPath = "\\test.com\clientdata\$DfsShareOfficeAbbr\$sClientFolderName\$sMatterNumberName"
                                
                                if (testPath $strDFSNamespaceRoot) {
                                    # Make sure that all folders exist on each server before starting DFS stuff.
                                    if (($sShareNameData) -and ($sShareNameData -ne "Select:")) {
                                        if (testPath "$sShareNameData\$sClientFolderName\$sMatterNumberName") {
                                            # Map the shared folder to a folder in the namespace.
                                            $strDFSPath = "$strDFSNamespaceRoot\$sClientFolderName\$sMatterNumberName\Data"
                                            $strServerPath = "$sShareNameData\$sClientFolderName\$sMatterNumberName"	
                                            if (start-job -scriptblock { Get-DfsnFolder $args[0] -ErrorAction Ignore } -ArgumentList $strDFSPath | Wait-Job | Receive-Job) { 
                                                postLog "createDFS : Folder $strDFSPath exists"
                                                #Start-Job -ScriptBlock { Remove-DfsnFolder -Path $Args[0] -Force } -ArgumentList $strDFSPath -Credential $global:serviceCredentials | Wait-Job | Receive-Job
                                            } else {
                                                Start-Job -ScriptBlock { New-DfsnFolder -Path $Args[0] $Args[1] } -ArgumentList $strDFSPath,$strServerPath -Credential $global:serviceCredentials | Wait-Job | Receive-Job		
                                            }
                                            postLog "createDFS : Created Namespace $strDFSPath `n Location: $strServerPath" "INFO"
                                        } else {
                                            postLog "createDFS : The path `"$sShareNameData\$sClientFolderName\$sMatterNumberName`" does not exist, `
                                                please fix this." "INFO"
                                        }
                                    }
                                    if (($sShareNameImages) -and ($sShareNameImages -ne "Select:")) {
                                        if (testPath "$sShareNameImages\$sClientFolderName\$sMatterNumberName") {
                                            # Map the shared folder to a folder in the namespace.
                                            $strDFSPath = "$strDFSNamespaceRoot\$sClientFolderName\$sMatterNumberName\Images"
                                            $strServerPath = "$sShareNameImages\$sClientFolderName\$sMatterNumberName"
                                            if (start-job -scriptblock { Get-DfsnFolder $args[0] -ErrorAction Ignore } -ArgumentList $strDFSPath | Wait-Job | Receive-Job) { 
                                                postLog "createDFS : Folder $strDFSPath exists"
                                                #Start-Job -ScriptBlock { Remove-DfsnFolder -Path $Args[0] -Force } -ArgumentList $strDFSPath -Credential $global:serviceCredentials | Wait-Job | Receive-Job
                                            } else {
                                                Start-Job -ScriptBlock { New-DfsnFolder -Path $Args[0] $Args[1] } -ArgumentList $strDFSPath,$strServerPath -Credential $global:serviceCredentials | Wait-Job | Receive-Job
                                            }
                                            postLog "createDFS : Created Namespace: $strDFSPath `n Location: $strServerPath" "INFO"
                                        } else {
                                            postLog "createDFS : The path `"$sShareNameImages\$sClientFolderName\$sMatterNumberName`" does not exist, `
                                                please fix this." "INFO"
                                        }
                                    }
                                    postStatus "Waiting for DFS Links to propagate..." "INFO"
                                    $i=0
                                    do {
                                        Start-Sleep -Seconds 1
                                        $i++
                                        postLog2 "Waiting for $strTestPath..." "INFO" "createDFS"
                                    } while (!(testPath $strTestPath) -and ($i -lt 30))
                                    if ($i -eq 30) {
                                        postStatus "Timed out waiting for DFS path, please confirm that DFS path exists!" "WARNING"
                                    } else {
                                        postStatus "DFS link creation complete!" "INFO"
                                    }
                                } else {
                                    postStatus "Namespace does not exist!" "WARNING"; return
                                }
                            }	
                            #endregion

                            #region Create Share Path Name
                            function CreateSharePath([string]$strSharePath) {
                                $arrSharePath = $strSharePath.Split("\")
                                $iSharePathCount = $arrSharePath.Count
                                if ($iSharePathCount -gt 4) {
                                    [string]$strClientNameNumber = $arrSharePath[4]
                                    if ($strClientNameNumber.Contains("`_")) {
                                        $strClientNumber = $strClientNameNumber.Substring(0,$strClientNameNumber.IndexOf("`_"))
                                        $strClientName = $strClientNameNumber.Replace("$strClientNumber`_", "")
                                    } else {
                                        $strClientNumber = $strClientNameNumber
                                        $strClientName = ""
                                    }
                                    if ($iSharePathCount -gt 5) {
                                        $strMatterNumberName = $arrSharePath[5]
                                        if ($strMatterNumberName.Contains("`_")) {
                                            $strMatterNumber = $strMatterNumberName.Substring(0,$strMatterNumberName.IndexOf("`_"))
                                            $strMatterName = $strMatterNumberName.Replace("$strMatterNumber`_","").Trim()
                                        } else {
                                            $strMatterNumber = $strMatterNumberName
                                            $strMatterName = ""
                                        }			
                                    }					
                                    if ($strMatterNumberName) {
                                        $ShareName = $strSharePath.Replace("\$strClientNameNumber\$strMatterNumberName","")
                                    } else {
                                        $ShareName = $strSharePath.Replace("\$strClientNameNumber","")
                                    }
                                    $arrSharePathResult = $ShareName, $strClientNumber, $strClientName, $strMatterNumber,$strMatterName
                                    return $arrSharePathResult
                                }	
                            }
                            #endregion

                            #region Verify Folder Information Form
                            function VerifyClientFolder($arrDataFolderList,$arrImagesFolderList, $arrUsers, $arrGroups) {
                            ########################################################################
                            # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
                            # Generated On: 1/9/2012 5:15 PM
                            # Generated By: dsuyemot
                            ########################################################################

                            #region Import the Assemblies
                            [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
                            [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
                            #endregion

                            #region Generated Form Objects
                            $VerifyClientFolder = New-Object System.Windows.Forms.Form
                            $listBox2 = New-Object System.Windows.Forms.ListBox
                            $listBox1 = New-Object System.Windows.Forms.ListBox
                            $label1 = New-Object System.Windows.Forms.Label
                            $groupBox1 = New-Object System.Windows.Forms.GroupBox
                            $changeButton = New-Object System.Windows.Forms.Button
                            $label2 = New-Object System.Windows.Forms.Label
                            $stopButton = New-Object System.Windows.Forms.Button
                            $continueButton = New-Object System.Windows.Forms.Button
                            $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
                            #endregion Generated Form Objects

                            #----------------------------------------------
                            #Generated Event Script Blocks
                            #----------------------------------------------
                            #Provide Custom Code for events specified in PrimalForms.
                            $changeButton_OnClick= 
                            {
                                $changeButton.enabled = $False
                                $stopButton.enabled = $False
                                $continueButton.enabled = $False
                                try {
                                    # Change Client Number & Client Name
                                    if ($listBox1.SelectedItem -or $listBox2.SelectedItem) {
                                        # Change Data Client, Matter Number & Share name
                                        if ($listBox1.SelectedItem) {
                                            $arrResult = CreateSharePath "$($listBox1.SelectedItem)"
                                            $ShareNameData = $arrResult[0]
                                            postLog "VerifyClientFolder : ShareNameData = $ShareNameData" "INFO"
                                            $strDataClientNumber = $arrResult[1]
                                            postLog "VerifyClientFolder : strDataClientNumber = $strDataClientNumber" "INFO"
                                            $strDataClientName = $arrResult[2]
                                            postLog "VerifyClientFolder : strDataClientName = $strDataClientName" "INFO"
                                            $strDataMatterNumber = $arrResult[3]
                                            postLog "VerifyClientFolder : strDataMatterNumber = $strDataMatterNumber" "INFO"
                                            $strDataMatterName = $arrResult[4]
                                            postLog "VerifyClientFolder : strDataMatterName = $strDataMatterName" "INFO"
                                            }
                                        # Change Images Client, Matter Number & Share name
                                        if ($listBox2.SelectedItem) {
                                            $arrResult = CreateSharePath "$($listBox2.SelectedItem)"
                                            $ShareNameImages = $arrResult[0]
                                            postLog "VerifyClientFolder : ShareNameImages = $ShareNameImages" "INFO"
                                            $strImagesClientNumber = $arrResult[1]
                                            postLog "VerifyClientFolder : strImagesClientNumber = $strImagesClientNumber" "INFO"
                                            $strImagesClientName = $arrResult[2]
                                            postLog "VerifyClientFolder : strImagesClientName = $strImagesClientName" "INFO"
                                            $strImagesMatterNumber = $arrResult[3]
                                            postLog "VerifyClientFolder : strImagesMatterNumber = $strImagesMatterNumber" "INFO"
                                            $strImagesMatterName = $arrResult[4]
                                            postLog "VerifyClientFolder : strImagesMatterName = $strImagesMatterName" "INFO"
                                        }
                                        # Prevent changing Data & Images to different shares
                                        if ($listBox1.SelectedItem -and $listBox2.SelectedItem) {	
                                            # Check if Client numbers match
                                            if ($strDataClientNumber -eq $strImagesClientNumber) {
                                                postLog "VerifyClientFolder : Data and Images Client numbers matched!" "INFO"
                                                
                                                # Update Client Name 
                                                $ClientNameTextBox.Text = $strDataClientName
                                                
                                                # Check if Client names exist
                                                if ($strDataClientName -and $strImagesClientName) {
                                                
                                                    #Check if Client names match
                                                    if ($strDataClientName -eq $strImagesClientName) {
                                                    postLog "VerifyClientFolder : Data and Images Client names matched!" "INFO"
                                                                                
                                                    # Update Client Number
                                                    $ClientNumberTextBox.Text = $strDataClientNumber

                                                    } else {
                                                        postStatus "Please select folders with the same Client Name!" "WARNING"
                                                        $changeButton.enabled = $True
                                                        $stopButton.enabled = $True
                                                        $continueButton.enabled = $True
                                                        return
                                                    }
                                                }
                                            } else {
                                                    postStatus "Please select folders with the same Client Number!" "WARNING"
                                                    $changeButton.enabled = $True
                                                    $stopButton.enabled = $True
                                                    $continueButton.enabled = $True
                                                    return
                                            }
                                            if ($strDataMatterNumber -and $strImagesMatterNumber) {
                                                if ($strDataMatterNumber -eq $strImagesMatterNumber) {
                                                    postLog "VerifyClientFolder : Data and Images Matter numbers matched!" "INFO"
                                                    
                                                    $MatterNumberTextBox.Text = $strDataMatterNumber
                                                    
                                                    # Check if Matter name exists
                                                    if ($strDataMatterName -and $strImagesMatterName) {
                                                    
                                                        # Check if Matter names match
                                                        if ($strDataMatterName -eq $strImagesMatterName) {
                                                        
                                                            # Update Matter Name
                                                            $MatterNameTextBox.Text = $strDataMatterName	
                                                        } else {
                                                            postStatus "Please select folders with the same Matter Name!" "WARNING"
                                                            $changeButton.enabled = $True
                                                            $stopButton.enabled = $True
                                                            $continueButton.enabled = $True
                                                            return
                                                        }	
                                                    }
                                                } else {
                                                    postStatus "Please select folders with the same Matter Name!" "WARNING"
                                                    $changeButton.enabled = $True
                                                    $stopButton.enabled = $True
                                                    $continueButton.enabled = $True
                                                    return
                                                }					
                                            } elseif ($strDataMatterNumber) {
                                                $MatterNameTextBox.Text = $strDataMatterName
                                                $MatterNumberTextBox.Text = $strDataMatterNumber
                                            } elseif ($strImagesMatterNumber) {
                                                $MatterNameTextBox.Text = $strImagesMatterName
                                                $MatterNumberTextBox.Text = $strImagesMatterNumber
                                            }
                                        } elseif ($listBox1.SelectedItem) {
                                            if ($strDataClientNumber) {					
                                                $ClientNameTextBox.Text = $strDataClientName
                                                $ClientNumberTextBox.Text = $strDataClientNumber
                                            }
                                            if ($strDataMatterNumber) {			
                                                $MatterNameTextBox.Text = $strDataMatterName
                                                $MatterNumberTextBox.Text = $strDataMatterNumber
                                            }
                                        } elseif ($listBox2.SelectedItem) {
                                            if ($strImagesClientNumber) {					
                                                $ClientNameTextBox.Text = $strImagesClientName
                                                $ClientNumberTextBox.Text = $strImagesClientNumber
                                            }
                                            if ($strImagesMatterNumber) {			
                                                $MatterNameTextBox.Text = $strImagesMatterName
                                                $MatterNumberTextBox.Text = $strImagesMatterNumber
                                            }
                                        }

                                        if ($ShareNameData) { $ShareDataComboBox.Text = $ShareNameData }
                                        if ($ShareNameImages) { $ShareImagesComboBox.Text = $ShareNameImages }
                                    
                                        # Check Accuracy
                                        postStatus "PLEASE VERIFY ALL INFORMATION IS CORRECT" "INFO"
                                        checkaccuracy $arrUsers $arrGroups
                                    } else {
                                        postStatus "Please Select a folder from the list!" "WARNING"
                                        $changeButton.enabled = $True
                                        $stopButton.enabled = $True
                                        $continueButton.enabled = $True
                                    }
                                } catch [System.Exception] {
                                    postStatus "ERROR!"
                                    postLog2 "$Error" "ERROR" "changeButton_OnClick" 
                                    return
                                }			
                            }
                            $continueButton_OnClick= 
                            {
                                $changeButton.enabled = $False
                                $stopButton.enabled = $False
                                $continueButton.enabled = $False
                                
                            #	$VerifyClientFolder.Close()
                                if (!$ClientNameTextBox.Text) {
                                    postStatus "You must select a pre-existing folder and click 'Change To' button if no Client Name exists!" "WARNING"
                                    $ClientNameTextBox.BackColor = [System.Drawing.Color]::LightCoral
                                    $changeButton.enabled = $True
                                    $stopButton.enabled = $True
                                    $continueButton.enabled = $True
                                } else {
                                    # Check Accuracy
                                    postStatus "PLEASE VERIFY ALL INFORMATION IS CORRECT" "INFO"
                                    checkaccuracy $arrUsers $arrGroups
                                }
                            }
                            $stopButton_OnClick= 
                            {
                                $changeButton.enabled = $False
                                $stopButton.enabled = $False
                                $continueButton.enabled = $False
                                
                                $VerifyClientFolder.Close()
                                $OKbuttonMain.enabled=$True
                                postStatus "Script Stopped!" "INFO"
                            }
                            $handler_VerifyClientFolder_Load=
                            {
                                if ($arrDataFolderList) { $arrDataFolderList | % { $listBox1.Items.Add($_) }}
                                if ($arrImagesFolderList) { $arrImagesFolderList | % { $listBox2.Items.Add($_) }}
                            }
                            $OnLoadForm_StateCorrection=
                            {#Correct the initial state of the form to prevent the .Net maximized form issue
                                $VerifyClientFolder.WindowState = $InitialFormWindowState
                            }

                            #----------------------------------------------
                            #region Generated Form Code
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 363
                            $System_Drawing_Size.Width = 391
                            $VerifyClientFolder.ClientSize = $System_Drawing_Size
                            $VerifyClientFolder.DataBindings.DefaultDataSourceUpdateMode = 0
                            $VerifyClientFolder.Name = "VerifyClientFolder"
                            $VerifyClientFolder.Text = "Possible Matching Folder(s) Found !"
                            $VerifyClientFolder.FormBorderStyle = 2
                            $VerifyClientFolder.add_Load($handler_VerifyClientFolder_Load)

                            $listBox2.DataBindings.DefaultDataSourceUpdateMode = 0
                            $listBox2.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 13
                            $System_Drawing_Point.Y = 138
                            $listBox2.Location = $System_Drawing_Point
                            $listBox2.Name = "listBox2"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 82
                            $System_Drawing_Size.Width = 366
                            $listBox2.Size = $System_Drawing_Size
                            $listBox2.TabIndex = 7

                            $VerifyClientFolder.Controls.Add($listBox2)

                            $listBox1.DataBindings.DefaultDataSourceUpdateMode = 0
                            $listBox1.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 13
                            $System_Drawing_Point.Y = 35
                            $listBox1.Location = $System_Drawing_Point
                            $listBox1.Name = "listBox1"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 82
                            $System_Drawing_Size.Width = 366
                            $listBox1.Size = $System_Drawing_Size
                            $listBox1.TabIndex = 2

                            $VerifyClientFolder.Controls.Add($listBox1)

                            $label1.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 13
                            $System_Drawing_Point.Y = 9
                            $label1.Location = $System_Drawing_Point
                            $label1.Name = "label1"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 260
                            $label1.Size = $System_Drawing_Size
                            $label1.TabIndex = 1
                            $label1.Text = "The following possible matches have been found:"

                            $VerifyClientFolder.Controls.Add($label1)


                            $groupBox1.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 13
                            $System_Drawing_Point.Y = 240
                            $groupBox1.Location = $System_Drawing_Point
                            $groupBox1.Name = "groupBox1"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 103
                            $System_Drawing_Size.Width = 366
                            $groupBox1.Size = $System_Drawing_Size
                            $groupBox1.TabIndex = 6
                            $groupBox1.TabStop = $False
                            $groupBox1.Text = "Please Choose:"

                            $VerifyClientFolder.Controls.Add($groupBox1)

                            $changeButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 7
                            $System_Drawing_Point.Y = 74
                            $changeButton.Location = $System_Drawing_Point
                            $changeButton.Name = "changeButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 123
                            $changeButton.Size = $System_Drawing_Size
                            $changeButton.TabIndex = 7
                            $changeButton.Text = "Change to Selected"
                            $changeButton.UseVisualStyleBackColor = $True
                            $changeButton.add_Click($changeButton_OnClick)

                            $groupBox1.Controls.Add($changeButton)

                            $label2.DataBindings.DefaultDataSourceUpdateMode = 0
                            $label2.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",8.25,0,3,1)

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 7
                            $System_Drawing_Point.Y = 29
                            $label2.Location = $System_Drawing_Point
                            $label2.Name = "label2"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 42
                            $System_Drawing_Size.Width = 353
                            $label2.Size = $System_Drawing_Size
                            $label2.TabIndex = 6
                            $label2.Text = "Select the pre-existing folder(s) you would like to change to and 
                                press Change to Selected or press Skip to keep original path."

                            $groupBox1.Controls.Add($label2)


                            $stopButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 258
                            $System_Drawing_Point.Y = 74
                            $stopButton.Location = $System_Drawing_Point
                            $stopButton.Name = "stopButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 102
                            $stopButton.Size = $System_Drawing_Size
                            $stopButton.TabIndex = 5
                            $stopButton.Text = "Stop and Return"
                            $stopButton.UseVisualStyleBackColor = $True
                            $stopButton.add_Click($stopButton_OnClick)

                            $groupBox1.Controls.Add($stopButton)


                            $continueButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 157
                            $System_Drawing_Point.Y = 74
                            $continueButton.Location = $System_Drawing_Point
                            $continueButton.Name = "continueButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 75
                            $continueButton.Size = $System_Drawing_Size
                            $continueButton.TabIndex = 4
                            $continueButton.Text = "Skip"
                            $continueButton.UseVisualStyleBackColor = $True
                            $continueButton.add_Click($continueButton_OnClick)

                            $groupBox1.Controls.Add($continueButton)

                            #endregion Generated Form Code

                            $VerifyClientFolder.Topmost = $True
                            #Save the initial state of the form
                            $InitialFormWindowState = $VerifyClientFolder.WindowState
                            #Init the OnLoad event to correct the initial state of the form
                            $VerifyClientFolder.add_Load($OnLoadForm_StateCorrection)
                            #Show the Form
                            $VerifyClientFolder.ShowDialog()| Out-Null


                            } #End Function
                            #endregion

                            #region Check for Existing Client/Matter Folders
                            function checkExistingClientFolders(
                                [string[]]$arrShares, 
                                [string]$sClientName, 
                                [string]$sClientNumber, 
                                [string]$sMatterName, 
                                [string]$sMatterNumber) {

                                $lsDirs = @()
                                # Create list of folders in share path
                                    foreach ($sSearchFolderPath in $arrShares) {
                                        postStatus "Checking for existing folders in $sSearchFolderPath..." "INFO"
                                        if (testPath $sSearchFolderPath) {
                                            # Search for Client folder match in share
                                            postLog "checkExistingClientFolders : Searching $sSearchFolderPath for `"$sClientNumber`"..." "INFO"
                                            try {
                                                $scriptBlock = {param($sSearchFolderPath,$sClientNumber) Get-ChildItem `
                                                        -Path $sSearchFolderPath -Name | ? {$_ -match $sClientNumber}}
                                                $lsMatchingClientFolders = Start-Job -ScriptBlock $scriptBlock -ArgumentList `
                                                        $sSearchFolderPath,$sClientNumber,([Environment]::CurrentDirectory = $Env:windir) `
                                                        -Credential $global:serviceCredentials | Wait-Job | Receive-Job
                                            } catch [System.Exception] {
                                                postStatus "Could not get a list of Client Folders!" "WARNING"
                                                $OKbuttonMain.enabled=$True
                                                return
                                            }
                                            # If Client folder match found search for matter
                                            if ($lsMatchingClientFolders) {
                                                foreach ($sMatchingClientFolder in $lsMatchingClientFolders) {
                                                    postLog "Client Folder: $sMatchingClientFolder" "INFO" "checkExistingClientFolders"
                                                    postLog "Matter Number: $sMatterNumber" "INFO" "checkExistingClientFolders"
                                                    postLog "Matter Name: $sMatterName" "INFO" "checkExistingClientFolders"
                                                    postLog "checkExistingClientFolders : Found matching Client folder $sMatchingClientFolder!" "INFO"
                                                    try {
                                                        postStatus "Checking for matter folders in $sSearchFolderPath\$sMatchingClientFolder" "INFO"
                                                        $sSearchDataClientFolderPath = "$sSearchFolderPath\$sMatchingClientFolder"
                                                        $scriptBlock = {param($sSearchDataClientFolderPath,$sMatterNumber) get-childitem `
                                                                -Path $sSearchDataClientFolderPath -Name | ? {$_ -match $sMatterNumber}}
                                                        $lsMatchingMatterFolders = Start-Job -ScriptBlock $scriptBlock -ArgumentList `
                                                                $sSearchDataClientFolderPath,$sMatterNumber,([Environment]::CurrentDirectory = $Env:windir) `
                                                                -Credential $global:serviceCredentials | Wait-Job | Receive-Job
                                                    } catch [System.Exception] {
                                                        postStatus "Could not get a list of Matter Folders!" "WARNING"
                                                        $OKbuttonMain.enabled=$True
                                                    }
                                                    # If Matter folders found, check for match
                                                    if ($lsMatchingMatterFolders) {		
                                                        foreach ($sMatterFolder in $lsMatchingMatterFolders) {
                                                            $arrMatterFolder = $sMatterFolder.Split("`_")
                                                            if ($arrMatterFolder[0] -eq "$sMatterNumber") {
                                                                
                                                                $lsDirs += "$sSearchFolderPath\$sMatchingClientFolder\$sMatterFolder"
                                                                postLog "checkExistingClientFolders : Matter Folder Path = $sSearchFolderPath\$sMatchingClientFolder\$sMatterFolder" "INFO"
                                                            }
                                                        }
                                                    } else {
                                                        if ("$sSearchFolderPath\$sClientNumber`_$sClientName" -ne "$sSearchFolderPath\$sMatchingClientFolder") {
                                                            $lsDirs += "$sSearchFolderPath\$sMatchingClientFolder"
                                                            postLog "checkExistingClientFolders : Client Folder Path = $sSearchFolderPath\$sMatchingClientFolder" "INFO"
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    return $lsDirs
                            }
                            #endregion

                            #region Search Menu Form
                            function UserSearchMenu {
                            ########################################################################
                            # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
                            # Generated On: 6/3/2021 11:03 AM
                            # Generated By: dsuyemot
                            ########################################################################

                            #region Import the Assemblies
                            [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
                            [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
                            #endregion

                            #region Generated Form Objects
                            $UserSearchMenu = New-Object System.Windows.Forms.Form
                            $RequiredLabel = New-Object System.Windows.Forms.Label
                            $UserOULabel = New-Object System.Windows.Forms.Label
                            $Criteria2Label = New-Object System.Windows.Forms.Label
                            $Criteria2TextBox = New-Object System.Windows.Forms.TextBox
                            $CANCELButton = New-Object System.Windows.Forms.Button
                            $OKButton = New-Object System.Windows.Forms.Button
                            $NamesToAddLabel = New-Object System.Windows.Forms.Label
                            $RemoveUserButton = New-Object System.Windows.Forms.Button
                            $UserAddedListBox = New-Object System.Windows.Forms.ListBox
                            $AddUserButton = New-Object System.Windows.Forms.Button
                            $SearchResultsLabel = New-Object System.Windows.Forms.Label
                            $UserSelectedListBox = New-Object System.Windows.Forms.ListBox
                            $UserSearchButton = New-Object System.Windows.Forms.Button
                            $Criteria1TextBox = New-Object System.Windows.Forms.TextBox
                            $Criteria1Label = New-Object System.Windows.Forms.Label
                            $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
                            #endregion Generated Form Objects

                            #----------------------------------------------
                            #Generated Event Script Blocks
                            #----------------------------------------------
                            #Provide Custom Code for events specified in PrimalForms.
                            $RemoveUserButton_Click= 
                            {
                                $strToRemove = $UserAddedListBox.SelectedItem
                                if($strToRemove) {
                                    [Void] $UserSelectedListBox.Items.add("$strToRemove")
                                    [Void] $UserAddedListBox.Items.remove("$strToRemove")
                                    postStatus "Name removed" "INFO"
                                }
                            }

                            $CANCELButton_Click= 
                            {
                                postStatus "Search Cancelled!" "INFO"
                                $UserSearchMenu.close()
                            }

                            $OKButton_Click= 
                            {
                                $UserSearchMenu.close()
                                $UserListBox.Items.Clear()
                                foreach($strAddedName in $UserAddedListBox.Items) {
                                    postLog "UserSearchMenu : Added $strAddedName" "INFO"
                                    $UserListBox.Items.Add($strAddedName)
                                }
                            }

                            $AddUserButton_Click= 
                            {
                                $strToAdd = $UserSelectedListBox.SelectedItem
                                if($strToAdd) { 
                                    [Void] $UserAddedListBox.Items.add("$strToAdd")
                                    [Void] $UserSelectedListBox.Items.remove("$strToAdd")
                                    postStatus "Name added" "INFO"
                                }
                            }

                            $UserSearchButton_Click= 
                            {
                                $UserSearchButton.Enabled = $False
                                postStatus "Searching..." "INFO"
                                $oUsers = searchUsername "$($Criteria1TextBox.Text)" "$($Criteria2TextBox.Text)"
                                $UserSelectedListBox.Items.Clear()
                                foreach ($oUser in $oUsers) {
                                    [Void] $UserSelectedListBox.Items.add($oUser.Name)
                                    $UserSearchMenu.Controls.Add($UserSelectedListBox)
                                }
                                
                                $UserSearchButton.Enabled = $True
                                postStatus "Search Complete!" "INFO"
                            }

                            $UserSearchMenu_Load= 
                            {
                                $UserAddedListBox.Items.Clear()
                                if($UserListBox.Items) {
                                    foreach($strAddedName in $UserListBox.Items) { [Void] $UserAddedListBox.Items.Add($strAddedName) }
                                }
                            }

                            $OnLoadForm_StateCorrection=
                            {#Correct the initial state of the form to prevent the .Net maximized form issue
                                $UserSearchMenu.WindowState = $InitialFormWindowState
                            }

                            #----------------------------------------------
                            #region Generated Form Code
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 273
                            $System_Drawing_Size.Width = 458
                            $UserSearchMenu.ClientSize = $System_Drawing_Size
                            $UserSearchMenu.DataBindings.DefaultDataSourceUpdateMode = 0
                            $UserSearchMenu.Name = "UserSearchMenu"
                            $UserSearchMenu.Text = "Select User Names to Add"
                            $UserSearchMenu.add_Load($UserSearchMenu_Load)
                            $UserSearchMenu.FormBorderStyle = 2

                            $RequiredLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 260
                            $System_Drawing_Point.Y = 53
                            $RequiredLabel.Location = $System_Drawing_Point
                            $RequiredLabel.Name = "RequiredLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 100
                            $RequiredLabel.Size = $System_Drawing_Size
                            $RequiredLabel.TabIndex = 17
                            $RequiredLabel.Text = "* Required"

                            $UserSearchMenu.Controls.Add($RequiredLabel)

                            $UserOULabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 260
                            $System_Drawing_Point.Y = 9
                            $UserOULabel.Location = $System_Drawing_Point
                            $UserOULabel.Name = "UserOULabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 15
                            $System_Drawing_Size.Width = 100
                            $UserOULabel.Size = $System_Drawing_Size
                            $UserOULabel.TabIndex = 0
                            $UserOULabel.Text = "OU:*"

                            $UserSearchMenu.Controls.Add($UserOULabel)

                            $Criteria2Label.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 154
                            $System_Drawing_Point.Y = 9
                            $Criteria2Label.Location = $System_Drawing_Point
                            $Criteria2Label.Name = "Criteria2Label"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 17
                            $System_Drawing_Size.Width = 100
                            $Criteria2Label.Size = $System_Drawing_Size
                            $Criteria2Label.TabIndex = 0
                            $Criteria2Label.Text = "Criteria 2:"

                            $UserSearchMenu.Controls.Add($Criteria2Label)

                            $Criteria2TextBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 154
                            $System_Drawing_Point.Y = 30
                            $Criteria2TextBox.Location = $System_Drawing_Point
                            $Criteria2TextBox.Name = "Criteria2"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 100
                            $Criteria2TextBox.Size = $System_Drawing_Size
                            $Criteria2TextBox.TabIndex = 1

                            $UserSearchMenu.Controls.Add($Criteria2TextBox)


                            $CANCELButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 360
                            $System_Drawing_Point.Y = 238
                            $CANCELButton.Location = $System_Drawing_Point
                            $CANCELButton.Name = "CANCELButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 75
                            $CANCELButton.Size = $System_Drawing_Size
                            $CANCELButton.TabIndex = 9
                            $CANCELButton.Text = "Cancel"
                            $CANCELButton.UseVisualStyleBackColor = $True
                            $CANCELButton.add_Click($CANCELButton_Click)

                            $UserSearchMenu.Controls.Add($CANCELButton)


                            $OKButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 279
                            $System_Drawing_Point.Y = 238
                            $OKButton.Location = $System_Drawing_Point
                            $OKButton.Name = "OKButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 75
                            $OKButton.Size = $System_Drawing_Size
                            $OKButton.TabIndex = 8
                            $OKButton.Text = "OK"
                            $OKButton.UseVisualStyleBackColor = $True
                            $OKButton.add_Click($OKButton_Click)

                            $UserSearchMenu.Controls.Add($OKButton)

                            $NamesToAddLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 279
                            $System_Drawing_Point.Y = 79
                            $NamesToAddLabel.Location = $System_Drawing_Point
                            $NamesToAddLabel.Name = "NamesToAddLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 16
                            $System_Drawing_Size.Width = 100
                            $NamesToAddLabel.Size = $System_Drawing_Size
                            $NamesToAddLabel.TabIndex = 0
                            $NamesToAddLabel.Text = "Names to Add:"

                            $UserSearchMenu.Controls.Add($NamesToAddLabel)


                            $RemoveUserButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 202
                            $System_Drawing_Point.Y = 158
                            $RemoveUserButton.Location = $System_Drawing_Point
                            $RemoveUserButton.Name = "RemoveUserButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 71
                            $RemoveUserButton.Size = $System_Drawing_Size
                            $RemoveUserButton.TabIndex = 6
                            $RemoveUserButton.Text = "< Remove"
                            $RemoveUserButton.UseVisualStyleBackColor = $True
                            $RemoveUserButton.add_Click($RemoveUserButton_Click)

                            $UserSearchMenu.Controls.Add($RemoveUserButton)

                            $UserAddedListBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $UserAddedListBox.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 279
                            $System_Drawing_Point.Y = 98
                            $UserAddedListBox.Location = $System_Drawing_Point
                            $UserAddedListBox.Name = "UserAddedListBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 134
                            $System_Drawing_Size.Width = 152
                            $UserAddedListBox.Size = $System_Drawing_Size
                            $UserAddedListBox.TabIndex = 7

                            $UserSearchMenu.Controls.Add($UserAddedListBox)


                            $AddUserButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 201
                            $System_Drawing_Point.Y = 118
                            $AddUserButton.Location = $System_Drawing_Point
                            $AddUserButton.Name = "AddUserButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 72
                            $AddUserButton.Size = $System_Drawing_Size
                            $AddUserButton.TabIndex = 5
                            $AddUserButton.Text = "Add >"
                            $AddUserButton.UseVisualStyleBackColor = $True
                            $AddUserButton.add_Click($AddUserButton_Click)

                            $UserSearchMenu.Controls.Add($AddUserButton)

                            $SearchResultsLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 33
                            $System_Drawing_Point.Y = 79
                            $SearchResultsLabel.Location = $System_Drawing_Point
                            $SearchResultsLabel.Name = "SearchResultsLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 16
                            $System_Drawing_Size.Width = 100
                            $SearchResultsLabel.Size = $System_Drawing_Size
                            $SearchResultsLabel.TabIndex = 0
                            $SearchResultsLabel.Text = "Search Results:"

                            $UserSearchMenu.Controls.Add($SearchResultsLabel)

                            $UserSelectedListBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $UserSelectedListBox.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 33
                            $System_Drawing_Point.Y = 98
                            $UserSelectedListBox.Location = $System_Drawing_Point
                            $UserSelectedListBox.Name = "UserSelectedListBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 134
                            $System_Drawing_Size.Width = 162
                            $UserSelectedListBox.Size = $System_Drawing_Size
                            $UserSelectedListBox.TabIndex = 4

                            $UserSearchMenu.Controls.Add($UserSelectedListBox)


                            $UserSearchButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 341
                            $System_Drawing_Point.Y = 27
                            $UserSearchButton.Location = $System_Drawing_Point
                            $UserSearchButton.Name = "UserSearchButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 71
                            $UserSearchButton.Size = $System_Drawing_Size
                            $UserSearchButton.TabIndex = 3
                            $UserSearchButton.Text = "Search"
                            $UserSearchButton.UseVisualStyleBackColor = $True
                            $UserSearchButton.add_Click($UserSearchButton_Click)

                            $UserSearchMenu.Controls.Add($UserSearchButton)

                            $Criteria1TextBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 33
                            $System_Drawing_Point.Y = 30
                            $Criteria1TextBox.Location = $System_Drawing_Point
                            $Criteria1TextBox.Name = "Criteria1"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 115
                            $Criteria1TextBox.Size = $System_Drawing_Size
                            $Criteria1TextBox.TabIndex = 0

                            $UserSearchMenu.Controls.Add($Criteria1TextBox)

                            $Criteria1Label.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 33
                            $System_Drawing_Point.Y = 9
                            $Criteria1Label.Location = $System_Drawing_Point
                            $Criteria1Label.Name = "Criteria1Label"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 17
                            $System_Drawing_Size.Width = 100
                            $Criteria1Label.Size = $System_Drawing_Size
                            $Criteria1Label.TabIndex = 0
                            $Criteria1Label.Text = "Criteria 1:"
                            $Criteria1Label.add_Click($handler_label1_Click)

                            $UserSearchMenu.Controls.Add($Criteria1Label)

                            #endregion Generated Form Code

                            #Save the initial state of the form
                            $InitialFormWindowState = $UserSearchMenu.WindowState
                            #Init the OnLoad event to correct the initial state of the form
                            $UserSearchMenu.add_Load($OnLoadForm_StateCorrection)
                            #Show the Form
                            $UserSearchMenu.ShowDialog()| Out-Null

                            } #End Function

                            #endregion

                            #region Group Search Menu
                            #Generated Form Function
                            function GroupSearchMenu {
                            ########################################################################
                            # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
                            # Generated On: 6/3/2021 10:45 AM
                            # Generated By: dsuyemot
                            ########################################################################

                            #region Import the Assemblies
                            [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
                            [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
                            #endregion

                            #region Generated Form Objects
                            $GroupSearchMenu = New-Object System.Windows.Forms.Form
                            $RequiredLabel = New-Object System.Windows.Forms.Label
                            $OULabel = New-Object System.Windows.Forms.Label
                            $GroupOUComboBox = New-Object System.Windows.Forms.ComboBox
                            $CANCELButton = New-Object System.Windows.Forms.Button
                            $OKButton = New-Object System.Windows.Forms.Button
                            $NamesToAddLabel = New-Object System.Windows.Forms.Label
                            $RemoveGroupButton = New-Object System.Windows.Forms.Button
                            $GroupAddedListBox = New-Object System.Windows.Forms.ListBox
                            $AddGroupButton = New-Object System.Windows.Forms.Button
                            $SearchResultsLabel = New-Object System.Windows.Forms.Label
                            $GroupSelectedListBox = New-Object System.Windows.Forms.ListBox
                            $GroupSearchButton = New-Object System.Windows.Forms.Button
                            $NameSearchTextBox = New-Object System.Windows.Forms.TextBox
                            $NameLabel = New-Object System.Windows.Forms.Label
                            $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
                            #endregion Generated Form Objects

                            #----------------------------------------------
                            #Generated Event Script Blocks
                            #----------------------------------------------
                            #Provide Custom Code for events specified in PrimalForms.
                            $AddGroupButton_Click= 
                            {
                                $strToAdd = $GroupSelectedListBox.SelectedItem
                                if($strToAdd) { 
                                    [Void] $GroupAddedListBox.Items.add("$strToAdd")
                                    [Void] $GroupSelectedListBox.Items.remove("$strToAdd")
                                    postStatus "Name added" "INFO"
                                }
                            }

                            $GroupSearch_Click= 
                            {
                                $GroupSearchButton.Enabled = $False
                                postStatus "Searching..." "INFO"

                                $oGroups = Get-ADGroup -Filter "Name -like `"*$($NameSearchTextBox.Text)*`"" -SearchBase "DC=test,DC=com"
                                $GroupSelectedListBox.Items.Clear()
                                foreach ($oGroup in $oGroups) {
                                [Void] $GroupSelectedListBox.Items.add($oGroup.Name)
                                $GroupSearchMenu.Controls.Add($GroupSelectedListBox)
                                }
                                
                                $GroupSearchButton.Enabled = $True
                                postStatus "Search Complete!" "INFO"
                            }

                            $CANCEL_Click= 
                            {
                                postStatus "Search Cancelled!" "INFO"
                                $GroupSearchMenu.close()
                            }

                            $OK_Click= 
                            {
                                $GroupSearchMenu.close()
                                $GroupListBox.Items.Clear()
                                $GroupAddedListBox.Items | % { 
                                    postLog "GroupSearchMenu : Added $_" "INFO"
                                    [Void] $GroupListBox.Items.Add($_) 
                                }
                            }

                            $RemoveGroupButton_Click= 
                            {
                                $strToRemove = $GroupAddedListBox.SelectedItem
                                if($strToRemove) {
                                    [Void] $GroupSelectedListBox.Items.add("$strToRemove")
                                    [Void] $GroupAddedListBox.Items.remove("$strToRemove")
                                    postStatus "Name removed" "INFO"
                                }
                            }

                            $GroupSearchMenu_Load= 
                            {
                                $GroupAddedListBox.Items.Clear()
                                if($GroupListBox.Items) {
                                    $GroupListBox.Items | % { [Void] $GroupAddedListBox.Items.Add($_) }
                                }
                            }

                            $OnLoadForm_StateCorrection=
                            {#Correct the initial state of the form to prevent the .Net maximized form issue
                                $GroupSearchMenu.WindowState = $InitialFormWindowState
                            }

                            #----------------------------------------------
                            #region Generated Form Code
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 273
                            $System_Drawing_Size.Width = 458
                            $GroupSearchMenu.ClientSize = $System_Drawing_Size
                            $GroupSearchMenu.DataBindings.DefaultDataSourceUpdateMode = 0
                            $GroupSearchMenu.Name = "GroupSearchMenu"
                            $GroupSearchMenu.Text = "Select Group Names to Add"
                            $GroupSearchMenu.add_Load($GroupSearchMenu_Load)
                            $GroupSearchMenu.FormBorderStyle = 2

                            $RequiredLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 260
                            $System_Drawing_Point.Y = 53
                            $RequiredLabel.Location = $System_Drawing_Point
                            $RequiredLabel.Name = "RequiredLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 100
                            $RequiredLabel.Size = $System_Drawing_Size
                            $RequiredLabel.TabIndex = 17
                            $RequiredLabel.Text = "* Required"

                            $GroupSearchMenu.Controls.Add($RequiredLabel)

                            $OULabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 260
                            $System_Drawing_Point.Y = 9
                            $OULabel.Location = $System_Drawing_Point
                            $OULabel.Name = "OULabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 15
                            $System_Drawing_Size.Width = 100
                            $OULabel.Size = $System_Drawing_Size
                            $OULabel.TabIndex = 0
                            $OULabel.Text = "OU:*"

                            $GroupSearchMenu.Controls.Add($OULabel)

                            $GroupOUComboBox.AutoCompleteMode = 3
                            $GroupOUComboBox.AutoCompleteSource = 64
                            $GroupOUComboBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $GroupOUComboBox.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 260
                            $System_Drawing_Point.Y = 29
                            $GroupOUComboBox.Location = $System_Drawing_Point
                            $GroupOUComboBox.Name = "GroupOfficeComboBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 21
                            $System_Drawing_Size.Width = 59
                            $GroupOUComboBox.Size = $System_Drawing_Size
                            $GroupOUComboBox.TabIndex = 2
                            $GroupOUComboBox.Text = "Select:"

                            $GroupSearchMenu.Controls.Add($GroupOUComboBox)


                            $CANCELButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 360
                            $System_Drawing_Point.Y = 238
                            $CANCELButton.Location = $System_Drawing_Point
                            $CANCELButton.Name = "CANCELButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 75
                            $CANCELButton.Size = $System_Drawing_Size
                            $CANCELButton.TabIndex = 9
                            $CANCELButton.Text = "Cancel"
                            $CANCELButton.UseVisualStyleBackColor = $True
                            $CANCELButton.add_Click($CANCEL_Click)

                            $GroupSearchMenu.Controls.Add($CANCELButton)


                            $OKButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 279
                            $System_Drawing_Point.Y = 238
                            $OKButton.Location = $System_Drawing_Point
                            $OKButton.Name = "OKButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 75
                            $OKButton.Size = $System_Drawing_Size
                            $OKButton.TabIndex = 8
                            $OKButton.Text = "OK"
                            $OKButton.UseVisualStyleBackColor = $True
                            $OKButton.add_Click($OK_Click)

                            $GroupSearchMenu.Controls.Add($OKButton)

                            $NamesToAddLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 279
                            $System_Drawing_Point.Y = 79
                            $NamesToAddLabel.Location = $System_Drawing_Point
                            $NamesToAddLabel.Name = "NamesToAddLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 16
                            $System_Drawing_Size.Width = 100
                            $NamesToAddLabel.Size = $System_Drawing_Size
                            $NamesToAddLabel.TabIndex = 0
                            $NamesToAddLabel.Text = "Names to Add:"

                            $GroupSearchMenu.Controls.Add($NamesToAddLabel)


                            $RemoveGroupButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 202
                            $System_Drawing_Point.Y = 158
                            $RemoveGroupButton.Location = $System_Drawing_Point
                            $RemoveGroupButton.Name = "RemoveGroupButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 71
                            $RemoveGroupButton.Size = $System_Drawing_Size
                            $RemoveGroupButton.TabIndex = 6
                            $RemoveGroupButton.Text = "< Remove"
                            $RemoveGroupButton.UseVisualStyleBackColor = $True
                            $RemoveGroupButton.add_Click($RemoveGroupButton_Click)

                            $GroupSearchMenu.Controls.Add($RemoveGroupButton)

                            $GroupAddedListBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $GroupAddedListBox.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 279
                            $System_Drawing_Point.Y = 98
                            $GroupAddedListBox.Location = $System_Drawing_Point
                            $GroupAddedListBox.Name = "GroupAddedListBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 134
                            $System_Drawing_Size.Width = 152
                            $GroupAddedListBox.Size = $System_Drawing_Size
                            $GroupAddedListBox.TabIndex = 7

                            $GroupSearchMenu.Controls.Add($GroupAddedListBox)


                            $AddGroupButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 201
                            $System_Drawing_Point.Y = 118
                            $AddGroupButton.Location = $System_Drawing_Point
                            $AddGroupButton.Name = "AddGroupButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 72
                            $AddGroupButton.Size = $System_Drawing_Size
                            $AddGroupButton.TabIndex = 5
                            $AddGroupButton.Text = "Add >"
                            $AddGroupButton.UseVisualStyleBackColor = $True
                            $AddGroupButton.add_Click($AddGroupButton_Click)

                            $GroupSearchMenu.Controls.Add($AddGroupButton)

                            $SearchResultsLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 33
                            $System_Drawing_Point.Y = 79
                            $SearchResultsLabel.Location = $System_Drawing_Point
                            $SearchResultsLabel.Name = "SearchResultsLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 16
                            $System_Drawing_Size.Width = 100
                            $SearchResultsLabel.Size = $System_Drawing_Size
                            $SearchResultsLabel.TabIndex = 0
                            $SearchResultsLabel.Text = "Search Results:"

                            $GroupSearchMenu.Controls.Add($SearchResultsLabel)

                            $GroupSelectedListBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $GroupSelectedListBox.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 33
                            $System_Drawing_Point.Y = 98
                            $GroupSelectedListBox.Location = $System_Drawing_Point
                            $GroupSelectedListBox.Name = "GroupSelectedListBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 134
                            $System_Drawing_Size.Width = 162
                            $GroupSelectedListBox.Size = $System_Drawing_Size
                            $GroupSelectedListBox.TabIndex = 4

                            $GroupSearchMenu.Controls.Add($GroupSelectedListBox)


                            $GroupSearchButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 341
                            $System_Drawing_Point.Y = 27
                            $GroupSearchButton.Location = $System_Drawing_Point
                            $GroupSearchButton.Name = "GroupSearchButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 71
                            $GroupSearchButton.Size = $System_Drawing_Size
                            $GroupSearchButton.TabIndex = 3
                            $GroupSearchButton.Text = "Search"
                            $GroupSearchButton.UseVisualStyleBackColor = $True
                            $GroupSearchButton.add_Click($GroupSearch_Click)

                            $GroupSearchMenu.Controls.Add($GroupSearchButton)

                            $NameSearchTextBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 33
                            $System_Drawing_Point.Y = 30
                            $NameSearchTextBox.Location = $System_Drawing_Point
                            $NameSearchTextBox.Name = "NameSearchTextBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 200
                            $NameSearchTextBox.Size = $System_Drawing_Size
                            $NameSearchTextBox.TabIndex = 0

                            $GroupSearchMenu.Controls.Add($NameSearchTextBox)

                            $NameLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 33
                            $System_Drawing_Point.Y = 9
                            $NameLabel.Location = $System_Drawing_Point
                            $NameLabel.Name = "NameLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 17
                            $System_Drawing_Size.Width = 100
                            $NameLabel.Size = $System_Drawing_Size
                            $NameLabel.TabIndex = 0
                            $NameLabel.Text = "Name"
                            $NameLabel.add_Click($handler_label1_Click)

                            $GroupSearchMenu.Controls.Add($NameLabel)

                            #endregion Generated Form Code

                            #Save the initial state of the form
                            $InitialFormWindowState = $GroupSearchMenu.WindowState
                            #Init the OnLoad event to correct the initial state of the form
                            $GroupSearchMenu.add_Load($OnLoadForm_StateCorrection)
                            #Show the Form
                            $GroupSearchMenu.ShowDialog()| Out-Null

                            } #End Function
                            #endregion

                            #region Get Share Names
                            function getShareNames($ComputerName, $ShareType)
                            {
                                try {
                                    $arrDataShares = Get-WmiObject Win32_Share -ComputerName $ComputerName -Credential $global:serviceCredentials `
                                            | ? {$_.Name -match $ShareType}
                                } catch [System.Exception] { 
                                    postLog2 "Error retrieving $ShareType shares" "ERROR" "getShareNames" 
                                }
                                return $arrDataShares
                            }
                            #endregion

                            #region Get Drive Space GB
                            function getDriveSpaceGB($strComputerName, $strShareName)
                            {
                                try {
                                    postLog "Computer Name : $strComputerName" "INFO" "getDriveSpaceGB"
                                    postLog "Share Name : $strShareName" "INFO" "getDriveSpaceGB"
                                    
                                    $oShare = Get-WmiObject win32_share -ComputerName $strComputerName -Filter "Name='$strShareName'" `
                                            -Credential $global:serviceCredentials
                                    $strSharePath = $oShare.Path
                                    postLog "Share Path : $strSharePath" "INFO" "getDriveSpaceGB"
                                    $junction = Invoke-Command -ComputerName $strComputerName -ScriptBlock { Get-Volume -FilePath "$Using:strSharePath" } -Credential $global:serviceCredentials   
                                    if ($junction) {
                                        postLog "Junction : $junction" "INFO" "getDriveSpaceGB"
                                        $volume = Invoke-Command -ComputerName $strComputerName -ScriptBlock { Get-Volume -FilePath "$Using:strSharePath" } -Credential $global:serviceCredentials
                                        $iDriveFreeSpace = $volume.SizeRemaining
                                    } else {
                                        $strShareDrive = $strSharePath.Substring(0,$strSharePath.IndexOf(":")+1)
                                        $oLogicalDisk = Get-WmiObject win32_logicalDisk -ComputerName $strComputerName `
                                                -Filter "DeviceID='$strShareDrive'" -Credential $global:serviceCredentials
                                        [long]$iDriveFreeSpace = $oLogicalDisk.FreeSpace
                                    }
                                        $iDriveFreeSpaceGB = "{0:N2}" -f ($iDriveFreeSpace / 1073741824)	
                                } catch {
                                    postLog2 "Unable to get drive space" "ERROR" "getDriveSpaceGB"
                                    return $null
                                }	
                                return $iDriveFreeSpaceGB
                            }
                            #endregion

                            #region Main Menu
                            function MainMenu {
                            ########################################################################
                            # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.9.0
                            # Generated On: 4/6/2011 1:02 PM
                            # Generated By: dsuyemot
                            ########################################################################

                            #region Import the Assemblies
                            [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
                            [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
                            #endregion

                            #region Generated Form Objects
                            $MainMenu = New-Object System.Windows.Forms.Form
                            $ReportIssueLinkLabel = New-Object System.Windows.Forms.Label
                            $statuspanel = New-Object System.Windows.Forms.Panel
                            $StatusListBox = New-Object System.Windows.Forms.ListBox
                            $MatterNameLabel = New-Object System.Windows.Forms.Label
                            $MatterNameTextBox = New-Object System.Windows.Forms.TextBox
                            $UserListBox = New-Object System.Windows.Forms.ListBox
                            $Cancelbutton = New-Object System.Windows.Forms.Button
                            $OKbuttonMain = New-Object System.Windows.Forms.Button
                            $ShareServerLabel = New-Object System.Windows.Forms.Label
                            $ShareServerTextBox = New-Object System.Windows.Forms.ComboBox
                            $ShareImagesLabel = New-Object System.Windows.Forms.Label
                            $ShareDataLabel = New-Object System.Windows.Forms.Label
                            $ShareOfficeLabel = New-Object System.Windows.Forms.Label
                            $MatterNumberLabel = New-Object System.Windows.Forms.Label
                            $ClientNumberLabel = New-Object System.Windows.Forms.Label
                            $ClientNameLabel = New-Object System.Windows.Forms.Label
                            $UserAddButton = New-Object System.Windows.Forms.Button
                            $ShareImagesComboBox = New-Object System.Windows.Forms.ComboBox
                            $ShareDataComboBox = New-Object System.Windows.Forms.ComboBox
                            $ShareOfficeComboBox = New-Object System.Windows.Forms.ComboBox
                            $MatterNumberTextBox = New-Object System.Windows.Forms.TextBox
                            $ClientNumberTextBox = New-Object System.Windows.Forms.TextBox
                            $ClientNameTextBox = New-Object System.Windows.Forms.TextBox
                            $UserNamesLabel = New-Object System.Windows.Forms.Label
                            $statusBar1 = New-Object System.Windows.Forms.StatusBar
                            $progressBar1 = New-Object System.Windows.Forms.ProgressBar
                            $RestoreButton = New-Object System.Windows.Forms.Button
                            $ResetButton = New-Object system.Windows.Forms.Button
                            $createSecurityGroupCheckBox = New-Object System.Windows.Forms.CheckBox
                            $createDfsCheckBox = New-Object System.Windows.Forms.CheckBox
                            $FillInGroupBox = New-Object System.Windows.Forms.GroupBox
                            $ShareDataTextBox = New-Object System.Windows.Forms.TextBox
                            $shareImagesTextBox = New-Object System.Windows.Forms.TextBox
                            $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
                            $FreeSpaceGroupBox = New-Object System.Windows.Forms.GroupBox
                            $GroupAddButton = New-Object System.Windows.Forms.Button
                            $GroupLabel = New-Object System.Windows.Forms.Label
                            $GroupListBox = New-Object System.Windows.Forms.ListBox

                            #endregion Generated Form Objects

                            #----------------------------------------------
                            #Generated Event Script Blocks
                            #----------------------------------------------
                            #Provide Custom Code for events specified in PrimalForms.
                            $handler_MainMenu_Load = 
                            {
                                $ShareOfficeComboBox.Enabled = $False
                                $ShareOfficeComboBox.Items.Clear()

                                if ($ShareOfficeComboBox.Text -eq "") { 
                                    $ShareOfficeComboBox.Text = "Select:"        
                                }
                                $ShareOfficeComboBox.Enabled = $True
                                foreach($strSite in $global:arrOffice) {
                                    $ShareOfficeComboBox.Items.add($strSite) | Out-Null
                                }
                            }
                            $OKbuttonMain_OnClick= 
                            {
                                postLog "OKbuttonMain_OnClick : Starting Process..." "INFO"
                                
                                $OKbuttonMain.enabled=$False
                                $ResetButton.enabled=$False
                                $RestoreButton.enabled=$False
                                [string]$ClientName=$ClientNameTextBox.Text
                                [string]$ClientNumber=$ClientNumberTextBox.Text
                                [string]$MatterNumber=$MatterNumberTextBox.Text
                                [string]$MatterName=$MatterNameTextBox.Text
                                [string]$ShareOfficeAbbr=$ShareOfficeComboBox.Text
                                [string]$ShareNameData=$ShareDataComboBox.Text
                                [string]$ShareNameImages=$ShareImagesComboBox.Text	

                                if ($MatterName -ne "") { 
                                    $MatterNumberName = $MatterNumber + "_" + $MatterName
                                } else {
                                    $MatterNumberName = $MatterNumber
                                }
                                if ($ShareNameData) {
                                    $strDataClientFolderPath = "$ShareNameData\$ClientNumber`_$ClientName" 
                                    $strDataMatterFolderPath = "$ShareNameData\$ClientNumber`_$ClientName\$MatterNumberName"
                                }
                                if ($ShareNameImages) {
                                    $strImagesClientFolderPath = "$ShareNameImages\$ClientNumber`_$ClientName" 
                                    $strImagesMatterFolderPath = "$ShareNameImages\$ClientNumber`_$ClientName\$MatterNumberName"
                                }
                                $strShareClientGroup = "$ShareOfficeAbbr $ClientNumber`_$ClientName"
                                $strShareMatterGroup = "$ShareOfficeAbbr $ClientNumber`_$MatterNumber"
                                
                                $ClientNameTextBox.BackColor = [System.Drawing.Color]::Empty
                                $MatterNumberTextBox.BackColor = [System.Drawing.Color]::Empty
                                $ClientNumberTextBox.BackColor = [System.Drawing.Color]::Empty
                                $MatterNameTextBox.BackColor = [System.Drawing.Color]::Empty
                                $UserListBox.BackColor = [System.Drawing.Color]::Empty
                                $ShareOfficeComboBox.BackColor = [System.Drawing.Color]::Empty

                                $sGroupOU = GetOfficeGroupOU $ShareOfficeAbbr
                                $strShareParentContainer = "ou=$sGroupOU,ou=$ShareOfficeAbbr,dc=test,dc=com"

                                $bFormIsFilled = $True
                                
                                # Check for special characters
                                $arrClientName = $ClientName.toCharArray()
                                foreach ($strChar in $arrClientName) { 
                                    if ($strChar -notmatch "\w") {
                                        postStatus "Client name does not conform to standard!" "WARNING"
                                        $ClientNameTextBox.BackColor = [System.Drawing.Color]::LightCoral
                                        $bFormIsFilled = $False
                                    }
                                }

                                # Check Client Number for letters
                                $arrClientNumber = $ClientNumber.toCharArray()
                                foreach ($strChar in $arrClientNumber) {
                                    if ($strChar -notmatch "\d") {
                                        postStatus "Client Number contains a letter!" "WARNING"
                                        $ClientNumberTextBox.BackColor = [System.Drawing.Color]::LightCoral
                                        $bFormIsFilled = $False
                                    }
                                }
                                
                                # Check for special characters in Matter Name if Matter Name exists
                                if ($MatterName) {
                                    $arrMatterName = $MatterName.toCharArray()
                                    foreach ($strChar in $arrMatterName) {
                                        if ($strChar -notmatch "\w") {
                                            postStatus "Matter Name does not conform to standard!" "WARNING"
                                            $MatterNameTextBox.BackColor = [System.Drawing.Color]::LightCoral
                                            $bFormIsFilled = $False
                                        }
                                    }
                                }
                                
                                # Check Matter number for letters
                                $arrMatterNumber = $MatterNumber.toCharArray()
                                foreach ($strChar in $arrMatterNumber) {
                                    if ($strChar -notmatch "\d") {
                                        postStatus "Matter Number contains a letter!" "WARNING"
                                        $MatterNumberTextBox.BackColor = [System.Drawing.Color]::LightCoral
                                        $bFormIsFilled = $False
                                    }
                                }

                                # Check Client Number is empty or not 6 characters
                                if(!($ClientNumberTextBox.Text) -or ($ClientNumberTextBox.Text).Length -ne 6) { 
                                    postStatus "Client Number is incorrect!" "WARNING"
                                    $ClientNumberTextBox.BackColor = [System.Drawing.Color]::LightCoral
                                    $bFormIsFilled = $False
                                }

                                # Check Matter Number is empty or not 4 characters
                                if(!$MatterNumberTextBox.Text -and ($MatterNumberTextBox.Text).Length -ne 4) {
                                    postStatus "Please fill out a matter number!" "WARNING"
                                    $MatterNumberTextBox.BackColor = [System.Drawing.Color]::LightCoral
                                    $bFormIsFilled = $False
                                }
                                if($ShareOfficeComboBox.Text -eq "Select:") {
                                    postStatus "Please select an office!" "WARNING"
                                    $ShareOfficeComboBox.BackColor = [System.Drawing.Color]::LightCoral
                                    $bFormIsFilled = $False
                                }
                                if($ShareDataComboBox.Text -eq "Select:" -and $ShareImagesComboBox.Text -eq "Select:") { 
                                    postStatus "Please select a share!" "WARNING"
                                    $ShareDataComboBox.BackColor = [System.Drawing.Color]::LightCoral
                                    $ShareImagesComboBox.BackColor = [System.Drawing.Color]::LightCoral
                                    $bFormIsFilled = $False
                                }

                                if (!$bFormIsFilled) { 
                                    $ResetButton.Enabled = $True
                                    $RestoreButton.Enabled = $True
                                    $OKbuttonMain.Enabled = $True
                                    return 
                                } 

                                saveDataToCache ($ClientName+","+$ClientNumber+","+$MatterNumber+","+$MatterName+","+`
                                    $ShareOfficeAbbr+","+$ShareNameData+","+$ShareNameImages)
                                
                                # Check path for Client Folder
                                postStatus "Checking for matching Client folder..." "INFO"
                                $lsDataDir = @()
                                $lsImagesDir = @()
                                $arrDataShares = $ShareDataComboBox.Items
                                $arrImagesShares = $ShareImagesComboBox.Items
                                if ($ShareNameData -ne "Select:") {
                                    $lsDataDir = checkExistingClientFolders $arrDataShares $ClientName $ClientNumber $MatterName $MatterNumber
                                }
                                if ($ShareNameImages -ne "Select:") {
                                    $lsImagesDir = checkExistingClientFolders $arrImagesShares $ClientName $ClientNumber $MatterName $MatterNumber
                                }
                                postLog "ClientNumber : $ClientNumber, MatterNumber : $MatterNumber, MatterName : $MatterName" "INFO"		
                                
                                # If matching client folder found, create prompt, otherwise continue
                                if ($lsDataDir -or $lsImagesDir) {

                                    if (!($lsDataDir)) { $lsDataDir = "None" }
                                    if (!($lsImagesDir)) { $lsImagesDir = "None" }

                                    postStatus "Verifying Client folder name(s)" "INFO"
                                    VerifyClientFolder $lsDataDir $lsImagesDir $UserListBox.Items $GroupListBox.Items
                                    [string]$ClientName=$ClientNameTextBox.Text
                                    [string]$ClientNumber=$ClientNumberTextBox.Text
                                    [string]$MatterNumber=$MatterNumberTextBox.Text
                                    [string]$MatterName=$MatterNameTextBox.Text
                                    [string]$ShareOfficeAbbr=$ShareOfficeComboBox.Text
                                    [string]$ShareNameData=$ShareDataComboBox.Text
                                    [string]$ShareNameImages=$ShareImagesComboBox.Text

                                    $MatterNumberName = $MatterNumber
                                    if ($MatterName) { 
                                        $MatterNumberName = "$MatterNumberName`_$MatterName"
                                    }

                                    if ($ShareNameData) {
                                        $strDataClientFolderPath = "$ShareNameData\$ClientNumber"
                                        if ($ClientName) {
                                            $strDataClientFolderPath = "$strDataClientFolderPath`_$ClientName" 
                                        }
                                        $strDataMatterFolderPath = "$strDataClientFolderPath\$MatterNumberName"
                                    }

                                    if ($ShareNameImages) {
                                        $strImagesClientFolderPath = "$ShareNameImages\$ClientNumber"
                                        if ($ClientName) {
                                            $strImagesClientFolderPath = "$strImagesClientFolderPath`_$ClientName" 
                                        }
                                        $strImagesMatterFolderPath = "$strImagesClientFolderPath\$MatterNumberName"
                                    }

                                    $strShareClientGroup = "$ShareOfficeAbbr $ClientNumber"
                                    if ($ClientName) {
                                        $strShareClientGroup = "$strShareClientGroup`_$ClientName"
                                    }

                                    $strShareMatterGroup = "$ShareOfficeAbbr $ClientNumber`_$MatterNumber"
                                } elseif ($ClientNameTextBox.Text -eq "") {
                                    postStatus "You must have a Client Name if you are creating a new folder structure!" "WARNING"
                                    $ClientNameTextBox.BackColor = [System.Drawing.Color]::LightCoral
                                    $OKbuttonMain.enabled=$True
                                } else {
                                    postStatus "Verifying accuracy..." "INFO"
                                    CheckAccuracy $UserListBox.Items $GroupListBox.Items
                                }		

                                if(!($OKbuttonMain.enabled) -and !($cancelButton.enabled)) {
                                    # Create Security
                                    createSecurityGroups $UserListBox.Items $GroupListBox.Items

                                    # Create Data & Images Folders
                                    createDataImagesFolders $ShareNameData $ShareNameImages $ClientName $ClientNumber $MatterName $MatterNumber

                                    # Create DFS Links
                                    createDFS $ShareNameData $ShareNameImages $ClientName $ClientNumber $MatterName $MatterNumber
                            
                                    # Pop ErrorForm for legal hold errors
                                    if (test-path $sLegalHoldBodyFilePath) {
                                        postStatus "Legal hold error detected!" "WARNING"
                                        errorForm $ShareOfficeAbbr $sUserEmailAddress $sEmailTo $sLegalHoldBodyFilePath $csSmtpEmailServer $csSubject
                                    }

                                    # Email notification if permissions incorrect
                                    if ($global:sErrorBodyText) {
                                        postStatus "Incorrect security rights have been detected on your created folder paths!" "WARNING"
                                        emailNotification $sUserEmailAddress $csInconsistentPermissionsEmailAddress "$global:sErrorBodyText" $csSubject $csSmtpEmailServer
                                        $global:sErrorBodyText = ""
                                    }
                                    
                                    #Reset Buttons and Fields on Main Menu
                                    $ClientNameTextBox.enabled=$True
                                    $ClientNumberTextBox.enabled=$True
                                    $MatterNameTextBox.enabled=$True
                                    $MatterNumberTextBox.enabled=$True
                                    $ShareOfficeComboBox.enabled=$True
                                    $ShareDataComboBox.enabled=$True
                                    $ShareImagesComboBox.enabled=$True
                                    $OKbuttonMain.enabled=$True
                                    $UserAddButton.enabled=$True
                                    $cancelButton.Enabled=$True
                                    $ResetButton.enabled=$True
                                    $RestoreButton.enabled=$True

                                    postStatus "Finished!" "INFO"
                                }
                            }

                            $UserAddButton_Click= 
                            {
                                $UserAddButton.enabled=$False
                                postStatus "...Search Window Open" "INFO"
                                postLog2 "Select User..." "INFO" "UserAddButton_Click"
                                UserSearchMenu
                                $UserAddButton.enabled=$True
                                postStatus "...Click OK to start" "INFO"
                                $UserListBox.BackColor = [System.Drawing.Color]::Empty
                            }
                            $GroupAddButton_Click= 
                            {
                                $GroupAddButton.Enabled = $False
                                postStatus "...Search Window Open" "INFO"
                                postLog2 "Select Group..." "INFO" "GroupAddButton_Click"
                                GroupSearchMenu
                                $GroupAddButton.Enabled = $True
                                postStatus "...Click OK to start" "INFO"
                                $GroupListBox.BackColor = [System.Drawing.Color]::Empty
                            }
                            $RestoreButton_Click=
                            {
                                $OKbuttonMain.enabled=$False
                                $Cancelbutton.enabled=$False
                                $RestoreButton.enabled=$False
                                reloadCachedData
                                $OKbuttonMain.enabled=$True
                                $Cancelbutton.enabled=$True
                                $RestoreButton.enabled=$True
                            }
                            $ResetButton_Click=
                            {
                                $OKbuttonMain.enabled=$False
                                $Cancelbutton.enabled=$False
                                $ResetButton.enabled=$False
                                $UserListBox.Items.Clear()
                                $GroupListBox.Items.Clear()
                                $ClientNameTextBox.Text = ""
                                $ClientNumberTextBox.Text = ""
                                $MatterNumberTextBox.Text = ""
                                $MatterNameTextBox.Text = ""
                                $ShareOfficeComboBox.Text = "Select:"
                                $ShareDataComboBox.Text = "Select:"
                                $ShareImagesComboBox.Text = "Select:"
                                $ShareDataComboBox.enabled = $False
                                $ShareImagesComboBox.enabled = $False
                                $ShareDataTextBox.Text = ""
                                $shareImagesTextBox.Text = ""
                                postStatus "Form data reset" "INFO"
                                $OKbuttonMain.enabled=$True
                                $Cancelbutton.enabled=$True
                                $ResetButton.enabled=$True
                            }
                            $Cancelbutton_OnClick= 
                            { 
                                $MainMenu.close()
                            }

                            $ShareOfficeComboBox_SelectedIndexChanged=
                            {
                                $ShareOfficeComboBox.BackColor = [System.Drawing.Color]::Empty
                                if ($ShareOfficeComboBox.Text -ne "Select:") {
                                    $ShareDataComboBox.enabled=$True
                                    $ShareDataComboBox.items.clear()
                                    $ShareDataComboBox.Text = "Searching..."
                                    $ShareImagesComboBox.enabled=$True
                                    $ShareImagesComboBox.items.clear()
                                    $ShareImagesComboBox.Text = "Searching..."
                                    postStatus "Searching..." "INFO"

                                    $DataShareOfficeAbbr = $ShareOfficeComboBox.Text
                                    $aServerNames = $aShareServerLocations
                                
                                    foreach($strDataShare in $aServerNames) {
                                        $sServerName = "$DataShareOfficeAbbr$strDataShare"
                                        if (testPath "\\$sServerName\c$" $sTempFolder) {
                                            postStatus "Getting Shares on \\$ServerName\c$" "INFO"
                                            
                                            $arrDataShares = getShareNames $sServerName "ShareData"
                                            
                                            if ($arrDataShares) {
                                                $arrDataShares | % {
                                                    $sDataSharePath = "\\$sServerName\$($_.Name)"
                                                    if (testPath $sDataSharePath) {
                                                        $ShareDataComboBox.Items.add($sDataSharePath)
                                                    }
                                                }
                                            }
                                            
                                            $arrImagesShares = getShareNames $sServerName "ShareImages"
                                            
                                            if ($arrImagesShares) {
                                                $arrImagesShares | % {
                                                    $sImagesSharePath = "\\$sServerName\$($_.Name)"
                                                    if (testPath $sImagesSharePath) {
                                                        $ShareImagesComboBox.Items.Add($sImagesSharePath)
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    $ShareDataComboBox.Sorted = $True
                                    $ShareImagesComboBox.Sorted = $True
                                    $ShareDataComboBox.Text = "Select:"
                                    $ShareImagesComboBox.Text = "Select:"
                                    postStatus "Press OK to Start" "INFO"
                                }
                            }

                            $ShareDataComboBox_SelectedIndexChanged=
                            {
                                if ($ShareDataComboBox.Text -ne "Select:") {
                                    postStatus "Querying available space on volume..." "INFO"
                                    $strShareDataComboBox = $ShareDataComboBox.Text
                                    $arrShareDataComboBox = $strShareDataComboBox.Split("\")
                                    $ComputerName = $arrShareDataComboBox[2]
                                    $strShareName = $strShareDataComboBox.Replace("\\$ComputerName\","")
                                    $iDataDriveFreeSpaceGB = getDriveSpaceGB $ComputerName $strShareName
                                    if ($iDataDriveFreeSpaceGB -ne $null) {
                                        $ShareDataTextBox.Text = "$iDataDriveFreeSpaceGB GB"
                                    }		
                                    postLog "ShareDataComboBox_SelectedIndexChanged : $strShareName = $iDataDriveFreeSpaceGB GB" "INFO"
                                    postStatus "Press OK to Start" "INFO"
                                }
                            }

                            $ShareImagesComboBox_SelectedIndexChanged=
                            {
                                if ($ShareImagesComboBox.Text -ne "Select:") {
                                    postStatus "Querying available space on volume..." "INFO"
                                    $strShareImagesComboBox = $ShareImagesComboBox.Text
                                    $arrShareImagesComboBox = $strShareImagesComboBox.Split("\")
                                    $ComputerName = $arrShareImagesComboBox[2]
                                    $strShareName = $strShareImagesComboBox.Replace("\\$ComputerName\","")
                                    $iImagesDriveFreeSpaceGB = getDriveSpaceGB $ComputerName $strShareName
                                    if ($iImagesDriveFreeSpaceGB -ne $null) {	
                                        $shareImagesTextBox.Text = "$iImagesDriveFreeSpaceGB GB"
                                    }
                                    postLog2 "$strShareName = $iImagesDriveFreeSpaceGB GB" "INFO" "ShareImagesComboBox_SelectedIndexChanged"
                                    postStatus "Press OK to Start" "INFO"
                                }
                            }

                            $ClientNameTextBox_GotFocus=
                            {
                                $ClientNameTextBox.BackColor = [System.Drawing.Color]::Empty
                            }
                            $ClientNumberTextBox_GotFocus=
                            {
                                $ClientNumberTextBox.BackColor = [System.Drawing.Color]::Empty
                            }
                            $MatterNumberTextBox_GotFocus=
                            {
                                $MatterNumberTextBox.BackColor = [System.Drawing.Color]::Empty
                            }
                            $MatterNameTextBox_GotFocus=
                            {
                                $MatterNameTextBox.BackColor = [System.Drawing.Color]::Empty
                            }

                            $OnLoadForm_StateCorrection=
                            {#Correct the initial state of the form to prevent the .Net maximized form issue
                                $MainMenu.WindowState = $InitialFormWindowState
                            }

                            #----------------------------------------------
                            #region Generated Form Code
                            $MainMenu.AcceptButton = $OKbuttonMain
                            $MainMenu.CancelButton = $Cancelbutton
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 509
                            $System_Drawing_Size.Width = 418
                            $MainMenu.ClientSize = $System_Drawing_Size
                            $MainMenu.DataBindings.DefaultDataSourceUpdateMode = 0
                            $MainMenu.FormBorderStyle = 2
                            $MainMenu.Name = "MainMenu"
                            $MainMenu.StartPosition = 1
                            $MainMenu.Text = "DFS Client-Matter Folder Link Creator"
                            $MainMenu.TopMost = $True
                            $MainMenu.add_Load($handler_MainMenu_Load)

                            $ReportIssueLinkLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 13
                            $System_Drawing_Point.Y = 445
                            $ReportIssueLinkLabel.Location = $System_Drawing_Point
                            $ReportIssueLinkLabel.Name = "ReportIssueLinkLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 150
                            $ReportIssueLinkLabel.Size = $System_Drawing_Size
                            $ReportIssueLinkLabel.TabIndex = 27
                            $ReportIssueLinkLabel.TabStop = $True
                            $ReportIssueLinkLabel.Text = "NOTE: Report Issues with DEPT"

                            $MainMenu.Controls.Add($ReportIssueLinkLabel)

                            $statusBar1.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 0
                            $System_Drawing_Point.Y = 480
                            $statusBar1.Location = $System_Drawing_Point
                            $statusBar1.Name = "statusBar1"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 29
                            $System_Drawing_Size.Width = 418
                            $statusBar1.Size = $System_Drawing_Size
                            $statusBar1.TabIndex = 21
                            $statusBar1.Text = "Idle"

                            $MainMenu.Controls.Add($statusBar1)


                            $Cancelbutton.DataBindings.DefaultDataSourceUpdateMode = 0
                            $Cancelbutton.DialogResult = 2

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 311
                            $System_Drawing_Point.Y = 440
                            $Cancelbutton.Location = $System_Drawing_Point
                            $Cancelbutton.Name = "Cancelbutton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 75
                            $Cancelbutton.Size = $System_Drawing_Size
                            $Cancelbutton.TabIndex = 19
                            $Cancelbutton.Text = "Cancel"
                            $Cancelbutton.UseVisualStyleBackColor = $True
                            $Cancelbutton.add_Click($Cancelbutton_OnClick)

                            $MainMenu.Controls.Add($Cancelbutton)


                            $OKbuttonMain.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 230
                            $System_Drawing_Point.Y = 440
                            $OKbuttonMain.Location = $System_Drawing_Point
                            $OKbuttonMain.Name = "OKbuttonMain"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 75
                            $OKbuttonMain.Size = $System_Drawing_Size
                            $OKbuttonMain.TabIndex = 18
                            $OKbuttonMain.Text = "OK"
                            $OKbuttonMain.UseVisualStyleBackColor = $True
                            $OKbuttonMain.add_Click($OKbuttonMain_OnClick)

                            $MainMenu.Controls.Add($OKbuttonMain)


                            $FillInGroupBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 13
                            $System_Drawing_Point.Y = 13
                            $FillInGroupBox.Location = $System_Drawing_Point
                            $FillInGroupBox.Name = "FillInGroupBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 412
                            $System_Drawing_Size.Width = 395
                            $FillInGroupBox.Size = $System_Drawing_Size
                            $FillInGroupBox.TabIndex = 26
                            $FillInGroupBox.TabStop = $False
                            $FillInGroupBox.Text = "Please Fill In:"

                            $MainMenu.Controls.Add($FillInGroupBox)

                            $GroupAddButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 304
                            $System_Drawing_Point.Y = 140
                            $GroupAddButton.Location = $System_Drawing_Point
                            $GroupAddButton.Name = "GroupAddButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 25
                            $GroupAddButton.Size = $System_Drawing_Size
                            $GroupAddButton.TabIndex = 32
                            $GroupAddButton.Text = "..."
                            $GroupAddButton.UseVisualStyleBackColor = $True
                            $GroupAddButton.add_Click($GroupAddButton_Click)

                            $FillInGroupBox.Controls.Add($GroupAddButton)

                            $GroupLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 104
                            $GroupLabel.Location = $System_Drawing_Point
                            $GroupLabel.Name = "GroupLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 100
                            $GroupLabel.Size = $System_Drawing_Size
                            $GroupLabel.TabIndex = 31
                            $GroupLabel.Text = "Groups to Add:"

                            $FillInGroupBox.Controls.Add($GroupLabel)

                            $GroupListBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $GroupListBox.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 141
                            $System_Drawing_Point.Y = 104
                            $GroupListBox.Location = $System_Drawing_Point
                            $GroupListBox.Name = "GroupListBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 56
                            $System_Drawing_Size.Width = 151
                            $GroupListBox.Size = $System_Drawing_Size
                            $GroupListBox.TabIndex = 30

                            $FillInGroupBox.Controls.Add($GroupListBox)

                            $RestoreButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 227
                            $System_Drawing_Point.Y = 349
                            $RestoreButton.Location = $System_Drawing_Point
                            $RestoreButton.Name = "restoreButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 65
                            $RestoreButton.Size = $System_Drawing_Size
                            $RestoreButton.TabIndex = 23
                            $RestoreButton.Text = "Restore"
                            $RestoreButton.UseVisualStyleBackColor = $True
                            $RestoreButton.add_Click($RestoreButton_Click)

                            $FillInGroupBox.Controls.Add($restoreButton)

                            $UserListBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $UserListBox.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 141
                            $System_Drawing_Point.Y = 42
                            $UserListBox.Location = $System_Drawing_Point
                            $UserListBox.Name = "UserListBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 56
                            $System_Drawing_Size.Width = 151
                            $UserListBox.Size = $System_Drawing_Size
                            $UserListBox.TabIndex = 1

                            $FillInGroupBox.Controls.Add($UserListBox)

                            $MatterNameLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 250
                            $MatterNameLabel.Location = $System_Drawing_Point
                            $MatterNameLabel.Name = "label1"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 155
                            $MatterNameLabel.Size = $System_Drawing_Size
                            $MatterNameLabel.TabIndex = 8
                            $MatterNameLabel.Text = "Matter Name: (Optional)"

                            $FillInGroupBox.Controls.Add($MatterNameLabel)

                            $UserNamesLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 42
                            $UserNamesLabel.Location = $System_Drawing_Point
                            $UserNamesLabel.Name = "UserNamesLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 17
                            $System_Drawing_Size.Width = 87
                            $UserNamesLabel.Size = $System_Drawing_Size
                            $UserNamesLabel.TabIndex = 0
                            $UserNamesLabel.Text = "Users to Add:"

                            $FillInGroupBox.Controls.Add($UserNamesLabel)


                            $UserAddButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 305
                            $System_Drawing_Point.Y = 78
                            $UserAddButton.Location = $System_Drawing_Point
                            $UserAddButton.Name = "UserAddButton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 25
                            $UserAddButton.Size = $System_Drawing_Size
                            $UserAddButton.TabIndex = 20
                            $UserAddButton.Text = "..."
                            $UserAddButton.UseVisualStyleBackColor = $True
                            $UserAddButton.add_Click($UserAddButton_Click)

                            $FillInGroupBox.Controls.Add($UserAddButton)


                            $ResetButton.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 305
                            $System_Drawing_Point.Y = 349
                            $ResetButton.Location = $System_Drawing_Point
                            $ResetButton.Name = "resetbutton"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 65
                            $ResetButton.Size = $System_Drawing_Size
                            $ResetButton.TabIndex = 22
                            $ResetButton.Text = "Reset"
                            $ResetButton.UseVisualStyleBackColor = $True
                            $ResetButton.add_Click($ResetButton_Click)

                            $FillInGroupBox.Controls.Add($ResetButton)

                            $MatterNameTextBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 192
                            $System_Drawing_Point.Y = 247
                            $MatterNameTextBox.Location = $System_Drawing_Point
                            $MatterNameTextBox.Name = "MatterNameTextBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 100
                            $MatterNameTextBox.Size = $System_Drawing_Size
                            $MatterNameTextBox.TabIndex = 9
                            $MatterNumberTextBox.MaxLength = 4

                            $FillInGroupBox.Controls.Add($MatterNameTextBox)

                            $ClientNameLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 180
                            $ClientNameLabel.Location = $System_Drawing_Point
                            $ClientNameLabel.Name = "ClientNameLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 17
                            $System_Drawing_Size.Width = 100
                            $ClientNameLabel.Size = $System_Drawing_Size
                            $ClientNameLabel.TabIndex = 2
                            $ClientNameLabel.Text = "Client Name:"

                            $FillInGroupBox.Controls.Add($ClientNameLabel)

                            $ClientNumberLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 203
                            $ClientNumberLabel.Location = $System_Drawing_Point
                            $ClientNumberLabel.Name = "ClientNumberLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 17
                            $System_Drawing_Size.Width = 100
                            $ClientNumberLabel.Size = $System_Drawing_Size
                            $ClientNumberLabel.TabIndex = 4
                            $ClientNumberLabel.Text = "Client Number:"

                            $FillInGroupBox.Controls.Add($ClientNumberLabel)

                            $MatterNumberLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 226
                            $MatterNumberLabel.Location = $System_Drawing_Point
                            $MatterNumberLabel.Name = "MatterNumberLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 17
                            $System_Drawing_Size.Width = 155
                            $MatterNumberLabel.Size = $System_Drawing_Size
                            $MatterNumberLabel.TabIndex = 6
                            $MatterNumberLabel.Text = "Matter Number: "

                            $FillInGroupBox.Controls.Add($MatterNumberLabel)

                            $ClientNameTextBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 192
                            $System_Drawing_Point.Y = 177
                            $ClientNameTextBox.Location = $System_Drawing_Point
                            $ClientNameTextBox.Name = "ClientNameTextBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 100
                            $ClientNameTextBox.Size = $System_Drawing_Size
                            $ClientNameTextBox.TabIndex = 3

                            $FillInGroupBox.Controls.Add($ClientNameTextBox)

                            $progressBar1.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 21
                            $System_Drawing_Point.Y = 375
                            $progressBar1.Location = $System_Drawing_Point
                            $progressBar1.Name = "progressBar1"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 23
                            $System_Drawing_Size.Width = 349
                            $progressBar1.Size = $System_Drawing_Size
                            $progressBar1.TabIndex = 3
                            $progressBar1.Visible = $False

                            $FillInGroupBox.Controls.Add($progressBar1)

                            $ClientNumberTextBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 192
                            $System_Drawing_Point.Y = 200
                            $ClientNumberTextBox.Location = $System_Drawing_Point
                            $ClientNumberTextBox.Name = "ClientNumberTextBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 100
                            $ClientNumberTextBox.Size = $System_Drawing_Size
                            $ClientNumberTextBox.TabIndex = 5
                            $ClientNumberTextBox.MaxLength = 6

                            $FillInGroupBox.Controls.Add($ClientNumberTextBox)

                            $MatterNumberTextBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 192
                            $System_Drawing_Point.Y = 223
                            $MatterNumberTextBox.Location = $System_Drawing_Point
                            $MatterNumberTextBox.Name = "MatterNumberTextBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 100
                            $MatterNumberTextBox.Size = $System_Drawing_Size
                            $MatterNumberTextBox.TabIndex = 7

                            $FillInGroupBox.Controls.Add($MatterNumberTextBox)

                            $ShareOfficeLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 273
                            $ShareOfficeLabel.Location = $System_Drawing_Point
                            $ShareOfficeLabel.Name = "ShareOfficeLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 17
                            $System_Drawing_Size.Width = 155
                            $ShareOfficeLabel.Size = $System_Drawing_Size
                            $ShareOfficeLabel.TabIndex = 10
                            $ShareOfficeLabel.Text = "Share Office Location: (XX)"

                            $FillInGroupBox.Controls.Add($ShareOfficeLabel)

                            $ShareDataLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 296
                            $ShareDataLabel.Location = $System_Drawing_Point
                            $ShareDataLabel.Name = "ShareDataLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 17
                            $System_Drawing_Size.Width = 100
                            $ShareDataLabel.Size = $System_Drawing_Size
                            $ShareDataLabel.TabIndex = 12
                            $ShareDataLabel.Text = "Share Data Folder:"

                            $FillInGroupBox.Controls.Add($ShareDataLabel)

                            $ShareImagesLabel.DataBindings.DefaultDataSourceUpdateMode = 0

                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 12
                            $System_Drawing_Point.Y = 318
                            $ShareImagesLabel.Location = $System_Drawing_Point
                            $ShareImagesLabel.Name = "ShareImagesLabel"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 17
                            $System_Drawing_Size.Width = 125
                            $ShareImagesLabel.Size = $System_Drawing_Size
                            $ShareImagesLabel.TabIndex = 14
                            $ShareImagesLabel.Text = "Share Images Folder:"
                            $ShareImagesLabel.add_Click($handler_ShareImagesLabel_Click)

                            $FillInGroupBox.Controls.Add($ShareImagesLabel)

                            $shareImagesComboBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $shareImagesComboBox.Enabled = $False
                            $shareImagesComboBox.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 137
                            $System_Drawing_Point.Y = 315
                            $shareImagesComboBox.Location = $System_Drawing_Point
                            $shareImagesComboBox.Name = "shareImagesComboBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 21
                            $System_Drawing_Size.Width = 155
                            $shareImagesComboBox.Size = $System_Drawing_Size
                            $shareImagesComboBox.TabIndex = 2
                            $shareImagesComboBox.Text = "Select:"
                            $ShareImagesComboBox.add_SelectedIndexChanged($ShareImagesComboBox_SelectedIndexChanged)

                            $FillInGroupBox.Controls.Add($shareImagesComboBox)

                            $ShareDataComboBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $ShareDataComboBox.Enabled = $False
                            $ShareDataComboBox.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 137
                            $System_Drawing_Point.Y = 293
                            $ShareDataComboBox.Location = $System_Drawing_Point
                            $ShareDataComboBox.Name = "ShareDataComboBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 21
                            $System_Drawing_Size.Width = 155
                            $ShareDataComboBox.Size = $System_Drawing_Size
                            $ShareDataComboBox.TabIndex = 1
                            $ShareDataComboBox.Text = "Select:"
                            $ShareDataComboBox.add_SelectedIndexChanged($ShareDataComboBox_SelectedIndexChanged)

                            $FillInGroupBox.Controls.Add($ShareDataComboBox)

                            $ShareOfficeComboBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $ShareOfficeComboBox.FormattingEnabled = $True
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 192
                            $System_Drawing_Point.Y = 270
                            $ShareOfficeComboBox.Location = $System_Drawing_Point
                            $ShareOfficeComboBox.Name = "shareOfficeComboBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 21
                            $System_Drawing_Size.Width = 100
                            $ShareOfficeComboBox.Size = $System_Drawing_Size
                            $ShareOfficeComboBox.TabIndex = 0
                            $ShareOfficeComboBox.add_SelectedIndexChanged($ShareOfficeComboBox_SelectedIndexChanged)

                            $FillInGroupBox.Controls.Add($ShareOfficeComboBox)

                            $FreeSpaceGroupBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 298
                            $System_Drawing_Point.Y = 273
                            $FreeSpaceGroupBox.Location = $System_Drawing_Point
                            $FreeSpaceGroupBox.Name = "FreeSpaceGroupBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 70
                            $System_Drawing_Size.Width = 85
                            $FreeSpaceGroupBox.Size = $System_Drawing_Size
                            $FreeSpaceGroupBox.TabIndex = 28
                            $FreeSpaceGroupBox.TabStop = $False
                            $FreeSpaceGroupBox.Text = "Free Space:"

                            $FillInGroupBox.Controls.Add($FreeSpaceGroupBox)
                            $ShareDataTextBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $ShareDataTextBox.Enabled = $False
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 6
                            $System_Drawing_Point.Y = 20
                            $ShareDataTextBox.Location = $System_Drawing_Point
                            $ShareDataTextBox.Name = "ShareDataTextBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 72
                            $ShareDataTextBox.Size = $System_Drawing_Size
                            $ShareDataTextBox.TabIndex = 4

                            $FreeSpaceGroupBox.Controls.Add($ShareDataTextBox)

                            $shareImagesTextBox.DataBindings.DefaultDataSourceUpdateMode = 0
                            $shareImagesTextBox.Enabled = $False
                            $System_Drawing_Point = New-Object System.Drawing.Point
                            $System_Drawing_Point.X = 6
                            $System_Drawing_Point.Y = 42
                            $shareImagesTextBox.Location = $System_Drawing_Point
                            $shareImagesTextBox.Name = "shareImagesTextBox"
                            $System_Drawing_Size = New-Object System.Drawing.Size
                            $System_Drawing_Size.Height = 20
                            $System_Drawing_Size.Width = 72
                            $shareImagesTextBox.Size = $System_Drawing_Size
                            $shareImagesTextBox.TabIndex = 5

                            $FreeSpaceGroupBox.Controls.Add($shareImagesTextBox)

                            #endregion Generated Form Code

                            #Customizations
                            $MainMenu.Text = "$csScriptName $csVersion"
                            $ClientNameTextBox.add_GotFocus($ClientNameTextBox_GotFocus)
                            $ClientNumberTextBox.add_GotFocus($ClientNumberTextBox_GotFocus)
                            $MatterNumberTextBox.add_GotFocus($MatterNumberTextBox_GotFocus)
                            $MatterNameTextBox.add_GotFocus($MatterNameTextBox_GotFocus)


                            $MainMenu.Topmost = $True
                            #Save the initial state of the form
                            $InitialFormWindowState = $MainMenu.WindowState
                            #Init the OnLoad event to correct the initial state of the form
                            $MainMenu.add_Load($OnLoadForm_StateCorrection)
                            #Show the Form
                            $MainMenu.ShowDialog()| Out-Null
                            }
                            #endregion


                            # Starting...
                            postLog2 "Starting DFS Client-Matter Folder Creation $csVersion..." "INFO"
                            postLog2 "PowerShell Version : $($PSVersionTable.PSVersion)" "INFO"

                            # Get Service Credentials
                            $global:serviceCredentials = retrieveServiceAccount
                            postLog2 "Service Account = $($global:serviceCredentials.UserName)" "INFO"

                            # Check for AD module
                            if ((Get-WindowsFeature RSAT-AD-PowerShell -Credential $global:serviceCredentials).InstallState -ne "Installed") {
                                    messageBox 'AD PowerShell tools are not installed' "0" "Install AD PowerShell Tools" "1"
                            }

                            postLog2 "Launched MainMenu" "INFO"
                            MainMenu
                        

Sample Output


                

Project Information

Key Features

  • Distributed File System (DFS) Access: Creates Folder Links Using DFS Architecture
  • Security: Creates Active Directory Security Groups and Applies Permissions on File Folders
  • Group or Single User Access: Gives Access to Users or Groups
  • Folder Structure: Folders are Arranged by Client-Matter
  • Folder Access: Can be Configured Across Geographic Locations