Is what you've listed the full script? If so I think the error results from the way you use $Credentials. There's no $cred variable in the script. Besides, as far as I know Connect-SPOService doesn't accept an object of type SharePointOnlineCredentials to be passed as an argument.
The modified script below works for me without any error