Public/Start-DataSanitization.ps1

Function Start-DataSanitization {
    <#
        .SYNOPSIS
        Accepts an filepath to a CSV or XLSX file containing AD User data and outputs a csv file to the same folder with " - Sanitized" appended to mark it as cleaned
        This function uses multiple other functions from this module, and takes
         
        .PARAMETER FilePath
        The path to the csv or excel file containing user object data you want to sanitize
 
        .OUTPUTS
        Outputs a file at the specified location with the sanitized data
 
        .EXAMPLE
        Start-DataSanitization "C:\Users\luke.hagar\Downloads\User Details.xlsx" -Verbose
    #>

    [CmdletBinding()]
    param (
        $FilePath
    )
    $Path = Get-ChildItem $FilePath
    $OutputPath = "$($Path.Directory)" + "\" + "$($Path.BaseName)" + " - Sanitized.csv"
    If ($FilePath -like "*.csv") {
        Write-Verbose "CSV Provided"
        $Data = Import-CSV $FilePath
    }
    If ($FilePath -like "*.xlsx") {
        Write-Verbose "XLSX Provided"
        Try { $Data = Import-Excel $FilePath }
        Catch { Install-Dependencies }
        Try { $Data = Import-Excel $FilePath }
        Catch { Throw $_ }
    }
    if ($null -ne $Data) {
        Write-Verbose "Getting Properties"
        $Properties = Get-Properties $Data
        Write-Verbose "Gathering Array values"
        $AllData = Get-AllArrayData -Array $Data -Properties $Properties
        Write-Verbose "Querying AD for Data"
        $Results = Get-ADUserList $AllData
        Write-Verbose "Outputting results"
        Write-Verbose "$($OutputPath)"
        $Results | Export-CSV $OutputPath -NoTypeInformation
    }
    else {
        Write-Warning "Issues Importing Data"
    }
}