I guess that would depend on how you define efficiency! You script, as written, looks fairly efficient if a bit wordy.
I'd start by eliminating the four lines of tests that load the values like "$ContainsTextFiles" and just do the Test-Path in the "if" conditional statements.
To make it easier to add additional file types without adding a separate code block for each one, take the data values from, say a hash.
See if this works. I haven't run it, but I don't think it contains any errors that would prevent it from running:
[CmdletBinding()]
Param (
[ValidateScript({$_ -match "\\$"})] # must end with a trailing "\"
[String]$Path
)
$Dest = "C:\Users\Ashley\OneDrive\Documents\PowerShell\Project\"
$suffix = [ordered]@{
'.txt' = 'Documents'
'.mp3' = 'Music'
'.jpg' = 'Pictures'
'.mp4' = 'Videos'
}
$suffix.GetEnumerator()|
ForEach-Object{
$p = "{0}*{1}" -f $Path, $_.Key
if ( (Test-Path -Path $p -PathType Leaf) ) {
$d = "{0}{1}\" -f $Dest, $_.Value
Move-Item -Path $p -Destination $d
Write-Host "All $($_.Value) files have been succesfully moved to $Dest\$($_.Value)"
}
Else {
Write-Error "No $($_.Key) files exist"
}
}