I've never seen a so easy script failing so royally:
$SQLServer = "localhost"
$cred = Get-Credential
invoke-sqlcmd -ServerInstance $SQLServer -Credential $cred -Query "select @@version"
the phrase says -Credentials is not recognized:
Invoke-Sqlcmd : A parameter cannot be found that matches parameter name 'Credential'.
So what is the point to have Get-Credential?
I see a lot of examples on internet and they all use it this way.
EDIT EXAMPLE: why this code is working with -Credential? Because -Credential is inside a function?
function Pause ($Message="Press any key to continue..."){ 
    "" 
    Write-Host $Message 
    $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") 
} 
function GetCompName{ 
    $SQLServer = Read-Host "Please enter a computer name or IP" 
    CheckHost 
} 
function CheckHost{ 
    $ping = gwmi Win32_PingStatus -filter "Address='$SQLServer'" 
    if($ping.StatusCode -eq 0){$pcip=$ping.ProtocolAddress; GetCollation} 
    else{Pause "Host $SQLServer down...Press any key to continue"; GetCompName} 
} 
function GetCollation {
    #Provide Database Name 
    $DatabaseName ="master"
    #Prompt for user credentials 
    $credential = Get-Credential
    $Query = "SELECT name, collation_name FROM sys.databases;  " 
    invoke-sqlcmd -ServerInstance $SQLServer -Database $DatabaseName -Credential $credential  -Query $Query | Format-Table
}
#---------Start Main-------------- 
$SQLServer = $args[0] 
if($SQLServer){CheckHost} 
else{GetCompName}

 
    